package com.siwei.mes.service.mixProportion.impl;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.base.BaseParams;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.common.util.*;
import com.siwei.mes.controller.common.UploadController;
import com.siwei.mes.entity.AssociationStorage;
import com.siwei.mes.entity.dto.PrintTaskExperimentInfo;
import com.siwei.mes.entity.experiment.ExperimentGenConfig;
import com.siwei.mes.entity.laboratory.DataHntPhb;
import com.siwei.mes.entity.laboratory.ImportList;
import com.siwei.mes.entity.mixproportion.*;
import com.siwei.mes.entity.system.User;
import com.siwei.mes.enums.CheckEnum;
import com.siwei.mes.enums.MaterialsEnum;
import com.siwei.mes.enums.SystemParamEnum;
import com.siwei.mes.mapper.AssociationStorageMapper;
import com.siwei.mes.mapper.experiment.ExperimentGenConfigMapper;
import com.siwei.mes.mapper.laboratory.DataHntPhbMapper;
import com.siwei.mes.mapper.laboratory.ImportListMapper;
import com.siwei.mes.mapper.laboratory.UploadLaboratoryMapper;
import com.siwei.mes.mapper.mixProportion.MixProportionMapper;
import com.siwei.mes.mapper.system.UserMapper;
import com.siwei.mes.service.mixProportion.MixProportionService;
import com.siwei.mes.service.mixProportion.MixProportionUpdateLogService;
import com.siwei.mes.service.system.SystemParamService;
import com.siwei.mes.upload.erp.UploadErpService;
import com.siwei.mes.upload.erp.entity.ErpPhbInfo;
import com.siwei.mes.upload.erp.entity.ErpPhbYclInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * 配合比表(MixProportion)表服务实现类
 *
 * @author dmwang
 * @since 2024-07-29 21:01:49
 */
@Slf4j
@Service
public class MixProportionServiceImpl implements MixProportionService {
    @Value("${createrId}")
    private String createrId;
    @Value(value = "${excel.mac}")
    private String ADDRESS_MAC;
    @Value(value = "${excel.windows}")
    private String ADDRESS_WINDOWS;
    @Value(value = "${excel.linux}")
    private String ADDRESS_LINUX;
    @Value(value = "${server.port}")
    private String port;
    @Resource
    private MixProportionMapper mixProportionMapper;
    @Resource
    private DataHntPhbMapper dataHntPhbMapper;
    @Resource
    private AssociationStorageMapper associationStorageMapper;
    @Resource
    private UserMapper userMapper;
    @Resource
    private UploadErpService uploadErpService;
    @Resource
    private MixProportionUpdateLogService mixProportionUpdateLogService;
    @Resource
    private UploadLaboratoryMapper m_uploadLaboratoryMapper;
    @Resource
    private SystemParamService systemParamService;
    @Resource
    private ImportListMapper importListMapper;
    @Resource
    private ExperimentGenConfigMapper experimentGenConfigMapper;

    @Override
    public Long create(MixProportion entity, boolean isDraw) {

        //原材料报告信息 json 转对象 非空判断
        MixProportionReport mixProportionReport = entity.getProportionMaterial().toJavaObject(MixProportionReport.class);

        List<NewRatio> ratioList = new ArrayList<>();

        assertTrue(mixProportionMapper.selectByPhbNo(entity.getProportionPhb()) != null, "该配合比编号已存在记录");

        assertReturn(mixProportionReport, entity, ratioList, isDraw);

        if (isDraw) {
            entity.init(true);
        }


        if (entity.getProportionTld() != null) {
            JSONObject proportionTld = entity.getProportionTld();

            MixProportionTld tld = proportionTld.toJavaObject(MixProportionTld.class);

            if (StringUtils.isNotBlank(tld.getQz()) && !tld.getQz().contains("mm")) {
                tld.setQz(tld.getQz() + "mm");
            }
            if (StringUtils.isNotBlank(tld.getHz()) && !tld.getHz().contains("mm")) {
                tld.setHz(tld.getHz() + "mm");
            }

            JSONObject jsonObject = JsonUtils.beanToObject(tld);
            entity.setProportionTld(jsonObject);

        }

        mixProportionMapper.insertSelective(entity);

        /**新增配合比修改日志*/
        mixProportionUpdateLogService.insertLog(entity.getId(), null, entity);

        //上传到协会
        try {
            uploadAssociation(entity);
            //更新上传状态
            MixProportion mixProportion = new MixProportion().setId(entity.getId()).setXhStatus("1").setXhReason("");
            mixProportionMapper.updateByPrimaryKeySelective(mixProportion);
        } catch (Exception e) {
            log.error("配合比上传协会错误 ：" + e.getMessage());

            MixProportion mixProportion = new MixProportion().setId(entity.getId()).setXhReason("配合比上传协会错误 ：" + e.getMessage());
            mixProportionMapper.updateByPrimaryKeySelective(mixProportion);
        }

        //上传至erp

        try {
            //status 1新增 2 修改 3 删除
            uploadMixProportionToErp(entity, "1");
        } catch (Exception e) {
            //记录上传失败原因
            log.error("上传配合比至erp 错误 ：" + e.getMessage());
            MixProportion mixProportion = new MixProportion().setId(entity.getId()).setErpReason("上传配合比至erp 错误 ：" + e.getMessage());
            mixProportionMapper.updateByPrimaryKeySelective(mixProportion);
        }

        for (NewRatio newRatio : ratioList) {
            MixProportion newMixProportion = entity;

            newMixProportion.setProportionPhb(newRatio.getXpebbh());
            newMixProportion.setProportionKsdj(newRatio.getXksdj());

            /**新增配合比修改日志*/
            mixProportionUpdateLogService.insertLog(newMixProportion.getId(), entity, newMixProportion);

            //上传到协会
            try {
                uploadAssociation(newMixProportion);
                //更新上传状态
                MixProportion mixProportion = new MixProportion().setId(newMixProportion.getId()).setXhStatus("1").setXhReason("");
                mixProportionMapper.updateByPrimaryKeySelective(mixProportion);
            } catch (Exception e) {
                log.error("配合比上传协会错误 ：" + e.getMessage());

                MixProportion mixProportion = new MixProportion().setId(newMixProportion.getId()).setXhReason("配合比上传协会错误 ：" + e.getMessage());
                mixProportionMapper.updateByPrimaryKeySelective(mixProportion);
            }

        }

        return entity.getId();
    }

    private void assertReturn(MixProportionReport mixProportionReport, MixProportion entity, List<NewRatio> ratioList, boolean isDraw) {

        //勾选上下兼容抗渗等级
        if (entity.getBackwardCompatible() != null && 1 == entity.getBackwardCompatible()) {
            if (entity.getNewRatio() != null) {
                for (Object o : entity.getNewRatio()) {

                    NewRatio newRatio = new NewRatio();

                    if (o instanceof LinkedHashMap) {
                        LinkedHashMap object = (LinkedHashMap) o;

                        if (object.get("xpebbh") != null && !"".equals(object.get("xpebbh"))) {
                            newRatio.setXpebbh(object.get("xpebbh").toString());
                        }
                        if (object.get("xksdj") != null && !"".equals(object.get("xksdj"))) {
                            newRatio.setXksdj(object.get("xksdj").toString());
                        }
                    } else if (o instanceof JSONObject) {
                        JSONObject object = (JSONObject) o;

                        if (object.get("xpebbh") != null && !"".equals(object.get("xpebbh"))) {
                            newRatio.setXpebbh(object.get("xpebbh").toString());
                        }
                        if (object.get("xksdj") != null && !"".equals(object.get("xksdj"))) {
                            newRatio.setXksdj(object.get("xksdj").toString());
                        }
                    }

                    ratioList.add(newRatio);
                }
                //判断是否相同配比
                Set<String> set = new HashSet<>();
                for (NewRatio ratio : ratioList) {
                    if (StringUtils.isNotBlank(ratio.getXpebbh())) {
                        assertTrue(ratio.getXpebbh().equals(entity.getProportionPhb()), "向下兼容抗渗等级的配合比编号不允许和当前配比相同！");
                        set.add(ratio.getXpebbh());
                    } else {
                        assertTrue(true, "为向下兼容抗渗等级的配合比编号不允许为空！");
                    }
                }
                //不相同说明有重复配合比编号
                if (set.size() != ratioList.size()) {
                    assertTrue(true, "为向下兼容抗渗等级的配合比编号不允许重复！");
                }
            }

        }

/*        if(!isDraw){
            return;
        }
        MixProportionReport.BgxxInfo sn = mixProportionReport.getSn();
        MixProportionReport.BgxxInfo water = mixProportionReport.getWater();
        MixProportionReport.BgxxInfo fmh = mixProportionReport.getFmh();
        MixProportionReport.BgxxInfo kzf = mixProportionReport.getKzf();
        MixProportionReport.BgxxInfo cgl = mixProportionReport.getCgl();
        MixProportionReport.BgxxInfo xgl = mixProportionReport.getXgl();
        MixProportionReport.BgxxInfo wjj1 = mixProportionReport.getWjj1();
        assertTrue(sn == null, "水泥对应试验报告不允许为空！");
        assertTrue(water == null, "水对应试验报告不允许为空！");
        assertTrue(fmh == null, "粉煤灰对应试验报告不允许为空！");
        assertTrue(kzf == null, "矿渣粉对应试验报告不允许为空！");
        assertTrue(cgl == null, "粗骨料对应试验报告不允许为空！");
        assertTrue(xgl == null, "细骨料对应试验报告不允许为空！");
        assertTrue(wjj1 == null, "外加剂1对应试验报告不允许为空！");


        //水泥
        if (sn.getPktzid() == null || sn.getPktzid().isEmpty()) {
            assertTrue(true, "水泥对应试验报告品控台账id不允许为空！");
        }
        if (sn.getScyl() == null || sn.getScyl().isEmpty()) {
            assertTrue(true, "水泥对应试验报告生产用量不允许为空！");
        }
        if (sn.getScylb() == null || sn.getScylb().isEmpty()) {
            assertTrue(true, "水泥对应试验报告生产用量比例不允许为空！");
        }
        if (sn.getDyyl() == null || sn.getDyyl().isEmpty()) {
            assertTrue(true, "水泥对应试验报告打印用量不允许为空！");
        }
        if (sn.getDyylb() == null || sn.getDyylb().isEmpty()) {
            assertTrue(true, "水泥对应试验报告打印用量比例不允许为空！");
        }
        if (sn.getWlmc() == null || sn.getWlmc().isEmpty()) {
            assertTrue(true, "水泥对应试验报告物料名称不允许为空！");
        }
        if (sn.getWlgg() == null || sn.getWlgg().isEmpty()) {
            assertTrue(true, "水泥对应试验报告物料规格不允许为空！");
        }
        if (sn.getWllx() == null || sn.getWllx().isEmpty()) {
            assertTrue(true, "水泥对应试验报告物料类型不允许为空！");
        }
        if (sn.getCj() == null || sn.getCj().isEmpty()) {
            assertTrue(true, "水泥对应试验报告厂家不允许为空！");
        }
        if (sn.getXhbgbh() == null || sn.getXhbgbh().isEmpty()) {
            assertTrue(true, "水泥对应试验报告协会报告编号不允许为空！");
        }


        //水
        if (water.getScyl() == null || water.getScyl().isEmpty()) {
            assertTrue(true, "水对应试验报告生产用量不允许为空！");
        }
        if (water.getScylb() == null || water.getScylb().isEmpty()) {
            assertTrue(true, "水对应试验报告生产用量比例不允许为空！");
        }
        if (water.getDyyl() == null || water.getDyyl().isEmpty()) {
            assertTrue(true, "水对应试验报告打印用量不允许为空！");
        }
        if (water.getDyylb() == null || water.getDyylb().isEmpty()) {
            assertTrue(true, "水对应试验报告打印用量比例不允许为空！");
        }


        //细骨料
        if (xgl.getPktzid() == null || xgl.getPktzid().isEmpty()) {
            assertTrue(true, "细骨料对应试验报告品控台账id不允许为空！");
        }
        if (xgl.getScyl() == null || xgl.getScyl().isEmpty()) {
            assertTrue(true, "细骨料对应试验报告生产用量不允许为空！");
        }
        if (xgl.getScylb() == null || xgl.getScylb().isEmpty()) {
            assertTrue(true, "细骨料对应试验报告生产用量比例不允许为空！");
        }
        if (xgl.getDyyl() == null || xgl.getDyyl().isEmpty()) {
            assertTrue(true, "细骨料对应试验报告打印用量不允许为空！");
        }
        if (xgl.getDyylb() == null || xgl.getDyylb().isEmpty()) {
            assertTrue(true, "细骨料对应试验报告打印用量比例不允许为空！");
        }
        if (xgl.getWlmc() == null || xgl.getWlmc().isEmpty()) {
            assertTrue(true, "细骨料对应试验报告物料名称不允许为空！");
        }
        if (xgl.getWlgg() == null || xgl.getWlgg().isEmpty()) {
            assertTrue(true, "细骨料对应试验报告物料规格不允许为空！");
        }
        if (xgl.getWllx() == null || xgl.getWllx().isEmpty()) {
            assertTrue(true, "细骨料对应试验报告物料类型不允许为空！");
        }
        if (xgl.getCj() == null || xgl.getCj().isEmpty()) {
            assertTrue(true, "细骨料对应试验报告厂家不允许为空！");
        }
        if (xgl.getXhbgbh() == null || xgl.getXhbgbh().isEmpty()) {
            assertTrue(true, "细骨料对应试验报告协会报告编号不允许为空！");
        }


        //粗骨料
        if (cgl.getPktzid() == null || cgl.getPktzid().isEmpty()) {
            assertTrue(true, "粗骨料对应试验报告品控台账id不允许为空！");
        }
        if (cgl.getScyl() == null || cgl.getScyl().isEmpty()) {
            assertTrue(true, "粗骨料对应试验报告生产用量不允许为空！");
        }
        if (cgl.getScylb() == null || cgl.getScylb().isEmpty()) {
            assertTrue(true, "粗骨料对应试验报告生产用量比例不允许为空！");
        }
        if (cgl.getDyyl() == null || cgl.getDyyl().isEmpty()) {
            assertTrue(true, "粗骨料对应试验报告打印用量不允许为空！");
        }
        if (cgl.getDyylb() == null || cgl.getDyylb().isEmpty()) {
            assertTrue(true, "粗骨料对应试验报告打印用量比例不允许为空！");
        }
        if (cgl.getWlmc() == null || cgl.getWlmc().isEmpty()) {
            assertTrue(true, "粗骨料对应试验报告物料名称不允许为空！");
        }
        if (cgl.getWlgg() == null || cgl.getWlgg().isEmpty()) {
            assertTrue(true, "粗骨料对应试验报告物料规格不允许为空！");
        }
        if (cgl.getWllx() == null || cgl.getWllx().isEmpty()) {
            assertTrue(true, "粗骨料对应试验报告物料类型不允许为空！");
        }
        if (cgl.getCj() == null || cgl.getCj().isEmpty()) {
            assertTrue(true, "粗骨料对应试验报告厂家不允许为空！");
        }
        if (cgl.getXhbgbh() == null || cgl.getXhbgbh().isEmpty()) {
            assertTrue(true, "粗骨料对应试验报告协会报告编号不允许为空！");
        }


        //粉煤灰
        if (fmh.getPktzid() == null || fmh.getPktzid().isEmpty()) {
            assertTrue(true, "粉煤灰对应试验报告品控台账id不允许为空！");
        }
        if (fmh.getScyl() == null || fmh.getScyl().isEmpty()) {
            assertTrue(true, "粉煤灰对应试验报告生产用量不允许为空！");
        }
        if (fmh.getScylb() == null || fmh.getScylb().isEmpty()) {
            assertTrue(true, "粉煤灰对应试验报告生产用量比例不允许为空！");
        }
        if (fmh.getDyyl() == null || fmh.getDyyl().isEmpty()) {
            assertTrue(true, "粉煤灰对应试验报告打印用量不允许为空！");
        }
        if (fmh.getDyylb() == null || fmh.getDyylb().isEmpty()) {
            assertTrue(true, "粉煤灰对应试验报告打印用量比例不允许为空！");
        }
        if (fmh.getWlmc() == null || fmh.getWlmc().isEmpty()) {
            assertTrue(true, "粉煤灰对应试验报告物料名称不允许为空！");
        }
        if (fmh.getWlgg() == null || fmh.getWlgg().isEmpty()) {
            assertTrue(true, "粉煤灰对应试验报告物料规格不允许为空！");
        }
        if (fmh.getWllx() == null || fmh.getWllx().isEmpty()) {
            assertTrue(true, "粉煤灰对应试验报告物料类型不允许为空！");
        }
        if (fmh.getCj() == null || fmh.getCj().isEmpty()) {
            assertTrue(true, "粉煤灰对应试验报告厂家不允许为空！");
        }
        if (fmh.getXhbgbh() == null || fmh.getXhbgbh().isEmpty()) {
            assertTrue(true, "粉煤灰对应试验报告协会报告编号不允许为空！");
        }


        //矿渣粉
        if (kzf.getPktzid() == null || kzf.getPktzid().isEmpty()) {
            assertTrue(true, "矿渣粉对应试验报告品控台账id不允许为空！");
        }
        if (kzf.getScyl() == null || kzf.getScyl().isEmpty()) {
            assertTrue(true, "矿渣粉对应试验报告生产用量不允许为空！");
        }
        if (kzf.getScylb() == null || kzf.getScylb().isEmpty()) {
            assertTrue(true, "矿渣粉对应试验报告生产用量比例不允许为空！");
        }
        if (kzf.getDyyl() == null || kzf.getDyyl().isEmpty()) {
            assertTrue(true, "矿渣粉对应试验报告打印用量不允许为空！");
        }
        if (kzf.getDyylb() == null || kzf.getDyylb().isEmpty()) {
            assertTrue(true, "矿渣粉对应试验报告打印用量比例不允许为空！");
        }
        if (kzf.getWlmc() == null || kzf.getWlmc().isEmpty()) {
            assertTrue(true, "矿渣粉对应试验报告物料名称不允许为空！");
        }
        if (kzf.getWlgg() == null || kzf.getWlgg().isEmpty()) {
            assertTrue(true, "矿渣粉对应试验报告物料规格不允许为空！");
        }
        if (kzf.getWllx() == null || kzf.getWllx().isEmpty()) {
            assertTrue(true, "矿渣粉对应试验报告物料类型不允许为空！");
        }
        if (kzf.getCj() == null || kzf.getCj().isEmpty()) {
            assertTrue(true, "矿渣粉对应试验报告厂家不允许为空！");
        }
        if (kzf.getXhbgbh() == null || kzf.getXhbgbh().isEmpty()) {
            assertTrue(true, "矿渣粉对应试验报告协会报告编号不允许为空！");
        }*/


    }

    private void assertUpdateReturn(MixProportion entity, List<NewRatio> ratioList) {

        //勾选上下兼容抗渗等级
        if (entity.getBackwardCompatible() != null && 1 == entity.getBackwardCompatible()) {
            if (entity.getNewRatio() != null) {
                for (Object o : entity.getNewRatio()) {

                    NewRatio newRatio = new NewRatio();

                    if (o instanceof LinkedHashMap) {
                        LinkedHashMap object = (LinkedHashMap) o;

                        if (object.get("xpebbh") != null && !"".equals(object.get("xpebbh"))) {
                            newRatio.setXpebbh(object.get("xpebbh").toString());
                        }
                        if (object.get("xksdj") != null && !"".equals(object.get("xksdj"))) {
                            newRatio.setXksdj(object.get("xksdj").toString());
                        }
                    } else if (o instanceof JSONObject) {
                        JSONObject object = (JSONObject) o;

                        if (object.get("xpebbh") != null && !"".equals(object.get("xpebbh"))) {
                            newRatio.setXpebbh(object.get("xpebbh").toString());
                        }
                        if (object.get("xksdj") != null && !"".equals(object.get("xksdj"))) {
                            newRatio.setXksdj(object.get("xksdj").toString());
                        }
                    }
                    ratioList.add(newRatio);
                }
                //判断是否相同配比
                Set<String> set = new HashSet<>();
                for (NewRatio ratio : ratioList) {
                    if (StringUtils.isNotBlank(ratio.getXpebbh())) {
                        assertTrue(ratio.getXpebbh().equals(entity.getProportionPhb()), "向下兼容抗渗等级的配合比编号不允许和当前配比相同！");
                        set.add(ratio.getXpebbh());
                    } else {
                        assertTrue(true, "为向下兼容抗渗等级的配合比编号不允许为空！");
                    }
                }
                //不相同说明有重复配合比编号
                if (set.size() != ratioList.size()) {
                    assertTrue(true, "为向下兼容抗渗等级的配合比编号不允许重复！");
                }
            }

        }

    }

    //上传至erp
    private void uploadMixProportionToErp(MixProportion entity, String status) {
        /**判断是否开启推送配合比到ERP*/
        String systemParamValue = systemParamService.selectBySystemCode(SystemParamEnum.PUSH_ERP_MIX, "0");
        if (StringUtils.isBlank(systemParamValue) || "0".equals(systemParamValue)) {
            log.info("系统参数：【{}】暂未开启推送配合比到ERP，不推送！", SystemParamEnum.PUSH_ERP_MIX);
            return;
        }
        /**这里组装推送的消息*/
        ErpPhbInfo erpPhbInfo = new ErpPhbInfo();
        if (StringUtils.isNotBlank(entity.getErpPhbId())) {
            log.info("推送到ERP的配比主键ID为：{}", entity.getErpPhbId());
            erpPhbInfo.setPhbId(entity.getErpPhbId());//配比主键ID（唯一）
        }
        erpPhbInfo.setPhbNo(entity.getProportionPhb());//配比编号
        erpPhbInfo.setTpz(entity.getProportionQddj());//砼品种
        erpPhbInfo.setLq(entity.getProportionLq());//龄期
        erpPhbInfo.setJbsj(NullUtils.ifNull(entity.getProportionJbsj()));//搅拌时间
        erpPhbInfo.setKzp("");//出砼门控制参数

        if (entity.getProportionTld() != null) {
            MixProportionTld tld = entity.getProportionTld().toJavaObject(MixProportionTld.class);
            if (tld.getQz() != null && !tld.getQz().isEmpty() && tld.getHz() != null && !tld.getHz().isEmpty()) {
                String value = tld.getQz() + "±" + tld.getHz();
                String tt = value.replace("mm", "");
                erpPhbInfo.setTld(tt);
            } else {
                erpPhbInfo.setTld("");
            }
        } else {
            erpPhbInfo.setTld("");
        }


        //删除
        if ("3".equals(status)) {
            erpPhbInfo.setPhbState("停止使用");////状态正在使用，尚未使用，停止使用
        } else {
            erpPhbInfo.setPhbState("正在使用");////状态正在使用，尚未使用，停止使用
        }
        erpPhbInfo.setRemark(entity.getProportionRemarks());//备注
        erpPhbInfo.setUsage("");//用途
        erpPhbInfo.setCreater(entity.getCreater() != null ? String.valueOf(entity.getCreater()) : "");//操作员

        //原材料报告信息 json 转对象
        MixProportionReport mixProportionReport = entity.getProportionMaterial().toJavaObject(MixProportionReport.class);
        MixProportionReport.BgxxInfo sn = mixProportionReport.getSn();
        MixProportionReport.BgxxInfo fmh = mixProportionReport.getFmh();
        MixProportionReport.BgxxInfo kzf = mixProportionReport.getKzf();
        MixProportionReport.BgxxInfo cgl = mixProportionReport.getCgl();
        MixProportionReport.BgxxInfo xgl = mixProportionReport.getXgl();
        MixProportionReport.BgxxInfo wjj1 = mixProportionReport.getWjj1();
        MixProportionReport.BgxxInfo wjj2 = mixProportionReport.getWjj2();
        MixProportionReport.BgxxInfo water = mixProportionReport.getWater();
        MixProportionReport.BgxxInfo wcl1 = mixProportionReport.getWcl1();
        /**配合比原材料用量*/
        List<ErpPhbYclInfo> phbYclInfoList = new ArrayList<>();

        if (sn != null && StringUtils.isNotBlank(sn.getWlmc()) && StringUtils.isNotBlank(sn.getWlgg()) && StringUtils.isNotBlank(sn.getWllx()) && StringUtils.isNotBlank(sn.getScyl())) {
            MaterialsEnum materialsEnum = MaterialsEnum.selectByCode(Integer.parseInt(sn.getWllx()));
            phbYclInfoList.add(new ErpPhbYclInfo().setName(sn.getWlmc()).setPzgg(sn.getWlgg())
                    .setCate(materialsEnum.getErpType())
                    .setYl(sn.getScyl()).setCw("0"));

            erpPhbInfo.setSnpz(sn.getWlgg());//水泥品种
        }
        if (StringUtils.isBlank(erpPhbInfo.getSnpz())) {
            erpPhbInfo.setSnpz("");//水泥品种
        }
        if (fmh != null && StringUtils.isNotBlank(fmh.getWlmc()) && StringUtils.isNotBlank(fmh.getWlgg()) && StringUtils.isNotBlank(fmh.getWllx()) && StringUtils.isNotBlank(fmh.getScyl())) {
            MaterialsEnum materialsEnum = MaterialsEnum.selectByCode(Integer.parseInt(fmh.getWllx()));
            phbYclInfoList.add(new ErpPhbYclInfo().setName(fmh.getWlmc()).setPzgg(fmh.getWlgg())
                    .setCate(materialsEnum.getErpType())
                    .setYl(fmh.getScyl()).setCw("0"));
        }
        if (kzf != null && StringUtils.isNotBlank(kzf.getWlmc()) && StringUtils.isNotBlank(kzf.getWlgg()) && StringUtils.isNotBlank(kzf.getWllx()) && StringUtils.isNotBlank(kzf.getScyl())) {
            MaterialsEnum materialsEnum = MaterialsEnum.selectByCode(Integer.parseInt(kzf.getWllx()));
            phbYclInfoList.add(new ErpPhbYclInfo().setName(kzf.getWlmc()).setPzgg(kzf.getWlgg())
                    .setCate(materialsEnum.getErpType())
                    .setYl(kzf.getScyl()).setCw("0"));
        }
        if (xgl != null && StringUtils.isNotBlank(xgl.getWlmc()) && StringUtils.isNotBlank(xgl.getWlgg()) && StringUtils.isNotBlank(xgl.getWllx()) && StringUtils.isNotBlank(xgl.getScyl())) {
            MaterialsEnum materialsEnum = MaterialsEnum.selectByCode(Integer.parseInt(xgl.getWllx()));
            phbYclInfoList.add(new ErpPhbYclInfo().setName(xgl.getWlmc()).setPzgg(xgl.getWlgg())
                    .setCate(materialsEnum.getErpType())
                    .setYl(xgl.getScyl()).setCw("0"));
        }
        if (cgl != null && StringUtils.isNotBlank(cgl.getWlmc()) && StringUtils.isNotBlank(cgl.getWlgg()) && StringUtils.isNotBlank(cgl.getWllx()) && StringUtils.isNotBlank(cgl.getScyl())) {
            MaterialsEnum materialsEnum = MaterialsEnum.selectByCode(Integer.parseInt(cgl.getWllx()));
            phbYclInfoList.add(new ErpPhbYclInfo().setName(cgl.getWlmc()).setPzgg(cgl.getWlgg())
                    .setCate(materialsEnum.getErpType())
                    .setYl(cgl.getScyl()).setCw("0"));

            erpPhbInfo.setSzgg(cgl.getWlgg());
        }

        if (StringUtils.isNotBlank(erpPhbInfo.getSzgg())) {
            erpPhbInfo.setSzgg("");
        }
        if (wjj1 != null && StringUtils.isNotBlank(wjj1.getWlmc()) && StringUtils.isNotBlank(wjj1.getWlgg()) && StringUtils.isNotBlank(wjj1.getWllx()) && StringUtils.isNotBlank(wjj1.getScyl())) {
            MaterialsEnum materialsEnum = MaterialsEnum.selectByCode(Integer.parseInt(wjj1.getWllx()));
            phbYclInfoList.add(new ErpPhbYclInfo().setName(wjj1.getWlmc()).setPzgg(wjj1.getWlgg())
                    .setCate(materialsEnum.getErpType())
                    .setYl(wjj1.getScyl()).setCw("0"));
        }
        if (wjj2 != null && StringUtils.isNotBlank(wjj2.getWlmc()) && StringUtils.isNotBlank(wjj2.getWlgg()) && StringUtils.isNotBlank(wjj2.getWllx()) && StringUtils.isNotBlank(wjj2.getScyl())) {
            MaterialsEnum materialsEnum = MaterialsEnum.selectByCode(Integer.parseInt(wjj2.getWllx()));
            phbYclInfoList.add(new ErpPhbYclInfo().setName(wjj2.getWlmc()).setPzgg(wjj2.getWlgg())
                    .setCate(materialsEnum.getErpType())
                    .setYl(wjj2.getScyl()).setCw("0"));
        }
        if (water != null && StringUtils.isNotBlank(water.getScyl()) && StringUtils.isNotBlank(water.getClgg()) && StringUtils.isNotBlank(water.getClmc())) {
            phbYclInfoList.add(new ErpPhbYclInfo().setName(water.getClmc()).setPzgg(water.getClgg())
                    .setCate(MaterialsEnum.WATER.getErpType())
                    .setYl(water.getScyl()).setCw("0"));
        }
        if (wcl1 != null && StringUtils.isNotBlank(wcl1.getScyl()) && StringUtils.isNotBlank(wcl1.getClgg()) && StringUtils.isNotBlank(wcl1.getClmc())) {
            phbYclInfoList.add(new ErpPhbYclInfo().setName(wcl1.getWlmc()).setPzgg(wcl1.getWlgg())
                    .setCate("掺合料")
                    .setYl(wcl1.getScyl()).setCw("0"));
        }
        erpPhbInfo.setYcls(phbYclInfoList);

        String phbId = uploadErpService.uploadPhbInfo(erpPhbInfo, true);//返回配合比id

        if (StringUtils.isNotBlank(phbId)) {
            //更新上传状态 与 erp 配合比id
            MixProportion mixProportion = new MixProportion().setId(entity.getId()).setErpStatus("1").setErpPhbId(phbId).setErpReason("");
            mixProportionMapper.updateByPrimaryKeySelective(mixProportion);
        } else if (StringUtils.isNotBlank(entity.getErpPhbId())) {
            MixProportion mixProportion = new MixProportion().setId(entity.getId()).setErpStatus("1").setErpPhbId(entity.getErpPhbId()).setErpReason("");
            mixProportionMapper.updateByPrimaryKeySelective(mixProportion);
        }
    }

    @Override
    public void update(MixProportion entity, boolean isDraw) {
        MixProportion mixProportion = mixProportionMapper.selectByPrimaryKey(entity.getId());
        assertTrue(mixProportion == null, "配合比表信息不存在");

        if (isDraw) {
            entity.init(false);
        }


        List<NewRatio> ratioList = new ArrayList<>();

        assertUpdateReturn(entity, ratioList);

        //塌落度默认加上单位
        if (entity.getProportionTld() != null) {
            JSONObject proportionTld = entity.getProportionTld();
            MixProportionTld tld = proportionTld.toJavaObject(MixProportionTld.class);
            if (StringUtils.isNotBlank(tld.getQz()) && !tld.getQz().contains("mm")) {
                tld.setQz(tld.getQz() + "mm");
            }
            if (StringUtils.isNotBlank(tld.getHz()) && !tld.getHz().contains("mm")) {
                tld.setHz(tld.getHz() + "mm");
            }
            JSONObject jsonObject = JsonUtils.beanToObject(tld);
            entity.setProportionTld(jsonObject);

        }

        mixProportionMapper.updateByPrimaryKeySelective(entity);

        /**新增配合比修改日志*/
        mixProportionUpdateLogService.insertLog(entity.getId(), mixProportion, entity);

        if (mixProportion.getErpPhbId() != null && !mixProportion.getErpPhbId().isEmpty()) {
            entity.setErpPhbId(mixProportion.getErpPhbId());
        }
        //上传到协会
        try {
            uploadAssociation(entity);
            //更新上传状态
            MixProportion mix = new MixProportion().setId(entity.getId()).setXhStatus("1").setXhReason("");
            mixProportionMapper.updateByPrimaryKeySelective(mix);
        } catch (Exception e) {
            log.error("配合比上传协会错误 ：" + e.getMessage());

            MixProportion mixPro = new MixProportion().setId(entity.getId()).setXhReason("配合比上传协会错误 ：" + e.getMessage());
            mixProportionMapper.updateByPrimaryKeySelective(mixPro);
        }

        //上传至erp
        try {
            uploadMixProportionToErp(entity, "2");
        } catch (Exception e) {
            //记录上传失败原因
            log.error("上传配合比至erp 错误 ：" + e.getMessage());
            MixProportion mix = new MixProportion().setId(entity.getId()).setErpReason("上传配合比至erp 错误 ：" + e.getMessage());
            mixProportionMapper.updateByPrimaryKeySelective(mix);
        }


        for (NewRatio newRatio : ratioList) {
            MixProportion newMixProportion = entity;

            newMixProportion.setProportionPhb(newRatio.getXpebbh());
            newMixProportion.setProportionKsdj(newRatio.getXksdj());

            /**新增配合比修改日志*/
            mixProportionUpdateLogService.insertLog(newMixProportion.getId(), entity, newMixProportion);

            //上传到协会
            try {
                uploadAssociation(newMixProportion);
                //更新上传状态
                MixProportion mix = new MixProportion().setId(newMixProportion.getId()).setXhStatus("1").setXhReason("");
                mixProportionMapper.updateByPrimaryKeySelective(mix);
            } catch (Exception e) {
                log.error("配合比上传协会错误 ：" + e.getMessage());

                MixProportion mix = new MixProportion().setId(newMixProportion.getId()).setXhReason("配合比上传协会错误 ：" + e.getMessage());
                mixProportionMapper.updateByPrimaryKeySelective(mix);
            }

        }

    }

    @Override
    public void delete(Long id) {
        MixProportion mixProportion = mixProportionMapper.selectByPrimaryKey(id);
        assertTrue(mixProportion == null, "配合比表信息不存在");
        mixProportion.setIsDel(1);
        mixProportionMapper.updateByPrimaryKeySelective(mixProportion);


        //上传至erp
        try {
            uploadMixProportionToErp(mixProportion, "3");
        } catch (Exception e) {
            //记录上传失败原因
            log.error("上传配合比至erp 错误 ：" + e.getMessage());
            MixProportion mix = new MixProportion().setId(mixProportion.getId()).setErpReason("上传配合比至erp 错误 ：" + e.getMessage());
            mixProportionMapper.updateByPrimaryKeySelective(mixProportion);
        }


    }

    @Override
    public PageInfo<MixProportion> getPage(PageQuery<MixProportion, MixProportion> query) {
        MixProportion searchParam = query.getParams().setIsDel(0);
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> mixProportionMapper.getList(searchParam));
    }

    @Override
    public MixProportion loadById(Long id) {
        return mixProportionMapper.loadById(id);
    }

    @Override
    public List<MixProportion> getAll(MixProportion entity) {
        return mixProportionMapper.getList(entity);
    }

    @Override
    public void compensate(MixProportion entity) {
        List<MixProportion> mixProportionList = mixProportionMapper.getList(new MixProportion().setIds(entity.getIds()));
        for (MixProportion mix : mixProportionList) {
            //上传到协会
            try {
                uploadAssociation(mix);
                //更新上传状态
                MixProportion mixProportion = new MixProportion().setId(mix.getId()).setXhStatus("1").setXhReason("");
                mixProportionMapper.updateByPrimaryKeySelective(mixProportion);

            } catch (Exception e) {
                log.error("配合比上传协会错误 ：" + e.getMessage());
                MixProportion mixProportion = new MixProportion().setId(mix.getId()).setXhReason("配合比上传协会错误 ：" + e.getMessage());
                mixProportionMapper.updateByPrimaryKeySelective(mixProportion);
            }
            //上传至erp
            try {
                uploadMixProportionToErp(mix, "1");
            } catch (Exception e) {
                //记录上传失败原因
                log.error("上传配合比至erp 错误 ：" + e.getMessage());
                MixProportion mixProportion = new MixProportion().setId(mix.getId()).setErpReason("上传配合比至erp 错误 ：" + e.getMessage());
                mixProportionMapper.updateByPrimaryKeySelective(mixProportion);
            }
        }
    }

    @Override
    public void historyProportion() {
      /*  try {
            List<DataHntPhb> listAll = dataHntPhbMapper.getListAll();
            for (DataHntPhb phb : listAll){
                MixProportion mix = new MixProportion();
                mix.setProportionPhb(phb.getMpno());
                mix.setProportionSjyj(phb.getMpdesignJudgeBy());
                mix.setProportionQddj(phb.getMpdesignStrength());
                mix.setProportionKzqd(phb.getMpbreakingStrength());
                mix.setProportionKsdj(phb.getMpwaterProofing());
                mix.setProportionQllz(null);//强氯离子

                if(phb.getMpdesignSlump() != null && !phb.getMpdesignSlump().isEmpty()){
                    String[] split = phb.getMpdesignSlump().split("±");
                    if(split != null){
                        MixProportionTld tld = new MixProportionTld();
                        if(split[0] != null){
                            tld.setQz(split[0]);
                        }
                        if(split[1] != null){
                            tld.setHz(split[1]);
                        }

                        mix.setProportionTld(tld.toJsonObject(tld));
                    }
                }

               mix.setProductionSjb(phb.getFiWaterCementRatio());
               mix.setProportionRemarks(phb.getMpdesignRemark());


                MixProportionReport mixProportionReport = new MixProportionReport();

                //查询原材料名称 规格 信息
                List<String> sampleIdList = new ArrayList<>();
                if(phb.getSampleIdC() != null){
                    sampleIdList.add(phb.getSampleIdC().toString());
                }
                if(phb.getSampleIdC() != null){
                    sampleIdList.add(phb.getSampleIdC().toString());
                }
                if(phb.getSampleIdC() != null){
                    sampleIdList.add(phb.getSampleIdC().toString());
                }
                if(phb.getSampleIdC() != null){
                    sampleIdList.add(phb.getSampleIdC().toString());
                }
                if(phb.getSampleIdC() != null){
                    sampleIdList.add(phb.getSampleIdC().toString());
                }

                //材料名称
                List<Map<String, Object>> itemSampleBySampleID1 = m_uploadLaboratoryMapper.findItemSampleBySampleID(sampleIdList);


                //水泥
                if(phb.getReportIdC() != null && !phb.getReportIdC().isEmpty()){
                    MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
                    bgxxInfo.setXhbgbh(phb.getReportIdC());


                }





               // mix.setProportionMaterial();

            }
        }catch (Exception e){
            log.error("同步历史配合比数据失败：" + e.getMessage());
        }*/

    }

    @Override
    public void importProportion(String filePath) {

        ImportParams params = new ImportParams();
        params.setTitleRows(0); // 设置标题行，
        params.setHeadRows(1); // 设置表头行，

        try {
            //读取excel 文件 转换至实体
            List<ExcelProportionDataObject> dataList = ExcelImportUtil.importExcel(new File(filePath), ExcelProportionDataObject.class, params);

            for (ExcelProportionDataObject dataObject : dataList) {
                //报告编号为空 则跳过
                if (dataObject.getCustomRatioNumber() == null || dataObject.getCustomRatioNumber().isEmpty()) {
                    continue;
                }
                //查询协会是否存在此配比
                DataHntPhb dataHntPhb = dataHntPhbMapper.findXhPhbByNo(dataObject.getCustomRatioNumber());

                MixProportion mix = new MixProportion();
                //存在 则查出来的值作为生产用量    不存在则新增品控与协会
                if (dataHntPhb == null) {
                    setLaboratory(mix, dataObject);
                } else {
                    setMixProportion(mix, dataHntPhb, dataObject);

                }

            }

        } catch (Exception e) {
            e.printStackTrace();
            log.error("读取excel文件失败：" + e.getMessage());
        }

    }


    @Override
    public void importProportionNew(String filePath) {

        ImportParams params = new ImportParams();
        params.setTitleRows(0); // 设置标题行，
        params.setHeadRows(1); // 设置表头行，

        try {
            //读取excel 文件 转换至实体
            List<ExcelProportionDataObject> dataList = ExcelImportUtil.importExcel(new File(filePath), ExcelProportionDataObject.class, params);

            for (ExcelProportionDataObject dataObject : dataList) {
                //报告编号为空 则跳过
                if (dataObject.getCustomRatioNumber() == null || dataObject.getCustomRatioNumber().isEmpty()) {
                    continue;
                }
                //查询协会是否存在此配比
                DataHntPhb dataHntPhb = dataHntPhbMapper.findXhPhbByNo(dataObject.getCustomRatioNumber());

                MixProportion mix = new MixProportion();

                if (dataHntPhb != null) {
                    setLaboratoryNew(mix, dataObject, dataHntPhb);
                }

            }

        } catch (Exception e) {
            e.printStackTrace();
            log.error("读取excel文件失败：" + e.getMessage());
        }

    }

    @Override
    public String exportProportion(HttpServletRequest request) {
        List<MixProportion> list = mixProportionMapper.getList(new MixProportion());
        List<ExcelMixProportion> dataObjectList = new ArrayList<>();
        for (MixProportion mix : list) {
            ExcelMixProportion dataObject = new ExcelMixProportion();
            dataObject.setCustomRatioNumber(mix.getProportionPhb());
            dataObject.setConcreteVariety(mix.getProportionQddj());

            if (mix.getProportionTld() != null) {
                MixProportionTld tld = mix.getProportionTld().toJavaObject(MixProportionTld.class);
                if (tld.getQz() != null && !tld.getQz().isEmpty() && tld.getHz() != null && !tld.getHz().isEmpty()) {
                    dataObject.setSlump(tld.getQz() + "±" + tld.getHz());
                }

            }
            dataObject.setLq(mix.getProportionLq());
            dataObject.setSjyj(mix.getProportionSjyj());
            dataObject.setKsdj(mix.getProportionKsdj());
            dataObject.setKzqd(mix.getProportionKzqd());
            dataObject.setQllz(mix.getProportionQllz());
            dataObject.setRemark(mix.getProportionRemarks());
            dataObject.setRz(mix.getProductionRz());
            dataObject.setSjb(mix.getProductionSjb());
            dataObject.setSl(mix.getProductionSl());
            dataObject.setWjjcl(mix.getProductionCl());
            dataObject.setErpPhbId(mix.getErpPhbId());
            if (mix.getReportDate() != null) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                String strDate = sdf.format(mix.getReportDate());
                dataObject.setBgrq(strDate);
            }
            dataObject.setJbsj(mix.getProportionJbsj());
            dataObject.setZjx(mix.getProportionZjx());
            dataObject.setBsx(mix.getProportionBsx());

            MixProportionReport mixProportionReport = mix.getProportionMaterial().toJavaObject(MixProportionReport.class);

            MixProportionReport.BgxxInfo sn = mixProportionReport.getSn();
            MixProportionReport.BgxxInfo water = mixProportionReport.getWater();
            MixProportionReport.BgxxInfo fmh = mixProportionReport.getFmh();
            MixProportionReport.BgxxInfo kzf = mixProportionReport.getKzf();
            MixProportionReport.BgxxInfo cgl = mixProportionReport.getCgl();
            MixProportionReport.BgxxInfo xgl = mixProportionReport.getXgl();
            MixProportionReport.BgxxInfo wjj1 = mixProportionReport.getWjj1();
            MixProportionReport.BgxxInfo wjj2 = mixProportionReport.getWjj2();

            if (sn != null) {
                dataObject.setSnmc(sn.getClmc());
                dataObject.setSngg(sn.getClgg());
                dataObject.setSnbaz(sn.getCertificateNo());
                dataObject.setSnbgbh(sn.getXhbgbh());
                dataObject.setSncj(sn.getCj());
                dataObject.setSncjjc(sn.getCjjc());
                dataObject.setSngys(sn.getGys());
                dataObject.setSngysjc(sn.getGysjc());
                dataObject.setSnph(sn.getBatch());
                dataObject.setSnyl(sn.getScyl());
                dataObject.setSnylbl(sn.getScylb());
                dataObject.setSnwlmc(sn.getWlmc());
                dataObject.setSnwlgg(sn.getWlgg());
            }

            if (water != null) {
                dataObject.setWatermc(water.getClmc());
                dataObject.setWatergg(water.getClgg());
                dataObject.setWateryl(water.getScyl());
                dataObject.setWaterylbl(water.getScylb());
            }

            if (fmh != null) {
                dataObject.setFmhmc(fmh.getClmc());
                dataObject.setFmhgg(fmh.getClgg());
                dataObject.setFmhbaz(fmh.getCertificateNo());
                dataObject.setFmhbgbh(fmh.getXhbgbh());
                dataObject.setFmhcj(fmh.getCj());
                dataObject.setFmhcjjc(fmh.getCjjc());
                dataObject.setFmhgys(fmh.getGys());
                dataObject.setFmhgysjc(fmh.getGysjc());
                dataObject.setFmhph(fmh.getBatch());
                dataObject.setFmhyl(fmh.getScyl());
                dataObject.setFmhylbl(fmh.getScylb());
                dataObject.setFmhwlmc(fmh.getWlmc());
                dataObject.setFmhwlgg(fmh.getWlgg());
            }

            if (kzf != null) {
                dataObject.setKzfmc(kzf.getClmc());
                dataObject.setKzfgg(kzf.getClgg());
                dataObject.setKzfbaz(kzf.getCertificateNo());
                dataObject.setKzfbgbh(kzf.getXhbgbh());
                dataObject.setKzfcj(kzf.getCj());
                dataObject.setKzfcjjc(kzf.getCjjc());
                dataObject.setKzfgys(kzf.getGys());
                dataObject.setKzfgysjc(kzf.getGysjc());
                dataObject.setKzfph(kzf.getBatch());
                dataObject.setKzfyl(kzf.getScyl());
                dataObject.setKzfylbl(kzf.getScylb());
                dataObject.setKzfwlmc(kzf.getWlmc());
                dataObject.setKzfwlgg(kzf.getWlgg());
            }


            if (cgl != null) {
                dataObject.setCglmc(cgl.getClmc());
                dataObject.setCglgg(cgl.getClgg());
                dataObject.setCglbaz(cgl.getCertificateNo());
                dataObject.setCglbgbh(cgl.getXhbgbh());
                dataObject.setCglcj(cgl.getCj());
                dataObject.setCglcjjc(cgl.getCjjc());
                dataObject.setCglgys(cgl.getGys());
                dataObject.setCglgysjc(cgl.getGysjc());
                dataObject.setCglph(cgl.getBatch());
                dataObject.setCglyl(cgl.getScyl());
                dataObject.setCglylbl(cgl.getScylb());
                dataObject.setCglwlmc(cgl.getWlmc());
                dataObject.setCglwlgg(cgl.getWlgg());
            }


            if (xgl != null) {
                dataObject.setXglmc(xgl.getClmc());
                dataObject.setXglgg(xgl.getClgg());
                dataObject.setXglbaz(xgl.getCertificateNo());
                dataObject.setXglbgbh(xgl.getXhbgbh());
                dataObject.setXglcj(xgl.getCj());
                dataObject.setXglcjjc(xgl.getCjjc());
                dataObject.setXglgys(xgl.getGys());
                dataObject.setXglgysjc(xgl.getGysjc());
                dataObject.setXglph(xgl.getBatch());
                dataObject.setXglyl(xgl.getScyl());
                dataObject.setXglylbl(xgl.getScylb());
                dataObject.setXglwlmc(xgl.getWlmc());
                dataObject.setXglwlgg(xgl.getWlgg());
            }


            if (wjj1 != null) {
                dataObject.setWjj1mc(wjj1.getClmc());
                dataObject.setWjj1gg(wjj1.getClgg());
                dataObject.setWjj1baz(wjj1.getCertificateNo());
                dataObject.setWjj1bgbh(wjj1.getXhbgbh());
                dataObject.setWjj1cj(wjj1.getCj());
                dataObject.setSncjjc(wjj1.getCjjc());
                dataObject.setWjj1gys(wjj1.getGys());
                dataObject.setWjj1gysjc(wjj1.getGysjc());
                dataObject.setWjj1ph(wjj1.getBatch());
                dataObject.setWjj1yl(wjj1.getScyl());
                dataObject.setWjj1ylbl(wjj1.getScylb());
                dataObject.setWjj1wlmc(wjj1.getWlmc());
                dataObject.setWjj1wlgg(wjj1.getWlgg());
            }


            if (wjj2 != null) {
                dataObject.setWjj2mc(wjj2.getClmc());
                dataObject.setWjj2gg(wjj2.getClgg());
                dataObject.setWjj2baz(wjj2.getCertificateNo());
                dataObject.setWjj2bgbh(wjj2.getXhbgbh());
                dataObject.setWjj2cj(wjj2.getCj());
                dataObject.setWjj2cjjc(wjj2.getCjjc());
                dataObject.setWjj2gys(wjj2.getGys());
                dataObject.setWjj2gysjc(wjj2.getGysjc());
                dataObject.setWjj2ph(wjj2.getBatch());
                dataObject.setWjj2yl(wjj2.getScyl());
                dataObject.setWjj2ylbl(wjj2.getScylb());
                dataObject.setWjj2wlmc(wjj2.getWlmc());
                dataObject.setWjj2wlgg(wjj2.getWlgg());
            }


            dataObjectList.add(dataObject);
        }

        // 设置导出参数
        ExportParams exportParams = new ExportParams();

        if (dataObjectList.isEmpty()) {
            /**这里是一条数据都没有默认添加一条空的*/
            dataObjectList.add(new ExcelMixProportion());
        }

        // 执行导出
        Workbook workbook = ExcelExportUtil.exportExcel(exportParams, ExcelMixProportion.class, dataObjectList);


        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String str = "phb" + sdf.format(new Date());

        /**获取盘符地址*/
        String pathName = getPathName();
        String filePath = pathName + str + ".xlsx";
        String fileName = str + ".xlsx";
        //将excel 写入到服务器地址
        try {
            /**判断目录是否存在*/
            File saveFile = new File(pathName);
            if (!saveFile.exists()) {
                saveFile.mkdirs();
            }

            FileOutputStream fos = new FileOutputStream(filePath);
            workbook.write(fos);
            fos.close();//关闭流

            /**获取可访问的excel地址*/
            String urlPath = UploadController.replacePathExcel(fileName, request, port);
            log.info("上传excel文件成功,路径：{},excel名称：{}", urlPath, fileName);

            return urlPath;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("数据导出失败" + e);
        }

        return null;
    }

    @Override
    public void frontEndImportProportion(MultipartFile file) {
        ImportParams params = new ImportParams();
        params.setTitleRows(0); // 设置标题行，
        params.setHeadRows(1); // 设置表头行，

        List<ExcelMixProportion> dataList = new ArrayList<>();
        try {
            dataList = ExcelImportUtil.importExcel(file.getInputStream(), ExcelMixProportion.class, params);
        } catch (Exception e) {
            log.error("读取excel文件失败：" + e.getMessage(), e);
            return;
        }
        for (ExcelMixProportion dataObject : dataList) {
            try {
                //配合比编号为空 则跳过
                if (dataObject.getCustomRatioNumber() == null || dataObject.getCustomRatioNumber().isEmpty()) {
                    log.info("配合比编号为空，直接跳过，对应数据：【{}】", JSON.toJSONString(dataObject));
                    continue;
                }

                //根据配合比编号查询品控是否存在
                MixProportion selectByPhbNo = mixProportionMapper.selectByPhbNo(dataObject.getCustomRatioNumber());

                MixProportion mixProportion = new MixProportion();

                //赋值
                setMixProportionNew(mixProportion, dataObject);

                if (selectByPhbNo == null) {
                    //新增逻辑
                    this.create(mixProportion, false);
                } else {
                    mixProportion.setId(selectByPhbNo.getId());
                    this.update(mixProportion, false);
                }

            } catch (Exception e) {
                log.error("导入配合比信息失败，配合比数据：【{}】,错误信息：【{}】", JSON.toJSONString(dataObject), e.getMessage(), e);
            }
        }
    }

    @Override
    public List<String> queryPhbNoNot() {
        List<String> result = new ArrayList();
        List<MixProportion> mixProportionList = mixProportionMapper.getList(new MixProportion());
        for(MixProportion mixProportion: mixProportionList){
            MixProportionReport mixProportionReport = JsonUtils.getObject(mixProportion.getProportionMaterial(), MixProportionReport.class);
            String snScyl = mixProportionReport.getSn().getScyl();
            String snDyyl = mixProportionReport.getSn().getDyyl();
            MixProportionReport.BgxxInfo water = mixProportionReport.getWater();//水
            if(isYlCheck(water,snScyl,snDyyl)){
                result.add(mixProportion.getProportionPhb()+",水");
                continue;
            }
            MixProportionReport.BgxxInfo sn = mixProportionReport.getSn();//水泥
            if(isYlCheck(sn,snScyl,snDyyl)){
                result.add(mixProportion.getProportionPhb()+",水泥");
                continue;
            }
            MixProportionReport.BgxxInfo fmh = mixProportionReport.getFmh();//粉煤灰
            if(isYlCheck(fmh,snScyl,snDyyl)){
                result.add(mixProportion.getProportionPhb()+",粉煤灰");
                continue;
            }
            MixProportionReport.BgxxInfo kzf = mixProportionReport.getKzf();//矿渣粉
            if(isYlCheck(kzf,snScyl,snDyyl)){
                result.add(mixProportion.getProportionPhb()+",矿渣粉");
                continue;
            }
            MixProportionReport.BgxxInfo cgl = mixProportionReport.getCgl();//粗骨料
            if(isYlCheck(cgl,snScyl,snDyyl)){
                result.add(mixProportion.getProportionPhb()+",粗骨料");
                continue;
            }
            MixProportionReport.BgxxInfo xgl = mixProportionReport.getXgl();//细骨料
            if(isYlCheck(xgl,snScyl,snDyyl)){
                result.add(mixProportion.getProportionPhb()+",外加剂1");
                continue;
            }
            MixProportionReport.BgxxInfo wjj1 = mixProportionReport.getWjj1();//外加剂1
            if(isYlCheck(wjj1,snScyl,snDyyl)){
                result.add(mixProportion.getProportionPhb()+",外加剂1");
                continue;
            }
            MixProportionReport.BgxxInfo wjj2 = mixProportionReport.getWjj2();//外加剂2
            if(isYlCheck(wjj2,snScyl,snDyyl)){
                result.add(mixProportion.getProportionPhb()+",外加剂2");
                continue;
            }
            MixProportionReport.BgxxInfo wcl1 = mixProportionReport.getWcl1();//外掺料1
            if(isYlCheck(wcl1,snScyl,snDyyl)){
                result.add(mixProportion.getProportionPhb()+",外掺料1");
                continue;
            }
            MixProportionReport.BgxxInfo wcl2 = mixProportionReport.getWcl2();//外掺料2
            if(isYlCheck(wcl2,snScyl,snDyyl)) {
                result.add(mixProportion.getProportionPhb()+",外掺料2");
            }
        }
        return result;
    }

    private boolean isYlCheck(MixProportionReport.BgxxInfo bgxxInfo,String scyl,String dyyl) {
        String bgxxScyl = bgxxInfo.getScyl();
        String bgxxDyyl = bgxxInfo.getDyyl();
        if(StringUtils.isBlank(bgxxScyl) || StringUtils.isBlank(bgxxDyyl) || "--".equals(bgxxScyl) || "--".equals(bgxxDyyl) || "---".equals(bgxxScyl) || "---".equals(bgxxDyyl)){
            return false;
        }
        log.info("配合比编号 bgxxScyl ：【{}】", bgxxScyl);
        BigDecimal bgxxScylInt = new BigDecimal(bgxxScyl);
        BigDecimal bgxxDyylInt = new BigDecimal(bgxxDyyl);
        BigDecimal scylInt = new BigDecimal(scyl);
        BigDecimal dyylInt = new BigDecimal(dyyl);

        if (scylInt.compareTo(BigDecimal.ZERO) == 0) {
            System.out.println("水泥用量不能为0");
            return false;
        }
        if (dyylInt.compareTo(BigDecimal.ZERO) == 0) {
            System.out.println("水泥用量不能为0");
            return false;
        }
        BigDecimal scRatio = bgxxScylInt.divide(scylInt, 2, RoundingMode.HALF_EVEN);
        BigDecimal dyRatio = bgxxDyylInt.divide(dyylInt, 2, RoundingMode.HALF_EVEN);
        if(!scRatio.toPlainString().equals(bgxxInfo.getScylb())){
            return true;
        }
        if(!dyRatio.toPlainString().equals(bgxxInfo.getDyylb())){
            return true;
        }
        return false;
    }
    private void setMixProportionNew(MixProportion mix, ExcelMixProportion dataObject) {
        //定死默认创建人为 id 配置文件 的
        mix.setUpdater(createrId == null ? null : Long.parseLong(createrId)).setUpdateTime(new Date()).setCreater(createrId == null ? null : Long.parseLong(createrId))
                .setCreateTime(new Date())
                .setIsDel(0);
        mix.setProportionPhb(dataObject.getCustomRatioNumber());
        mix.setProportionSjyj(dataObject.getSjyj());
        mix.setProportionQddj(dataObject.getConcreteVariety());
        mix.setProportionKzqd(dataObject.getKzqd());
        mix.setProportionKsdj(dataObject.getKsdj());
        mix.setProportionQllz(dataObject.getQllz());//强氯离子
        mix.setProportionLq(dataObject.getLq());

        mix.setErpPhbId(dataObject.getErpPhbId());

        if (StringUtils.isNotBlank(dataObject.getBgrq())) {
            try {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                Date parse = sdf.parse(dataObject.getBgrq());
                mix.setReportDate(parse);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        mix.setProportionJbsj(dataObject.getJbsj());
        mix.setProportionZjx(dataObject.getZjx());
        mix.setProportionBsx(dataObject.getBsx());

        List<String> asList = Arrays.asList("P6", "P8", "P10", "P12");

        //是否向下兼容
        if (StringUtils.isNotBlank(dataObject.getKsdj()) && asList.contains(dataObject.getKsdj())) {
            mix.setBackwardCompatible(1);

            List<NewRatio> ratioList = new ArrayList<>();
            String newRatioString = "";
            if ("P12".equals(dataObject.getKsdj())) {
                NewRatio ratio = new NewRatio();
                ratio.setXpebbh(dataObject.getCustomRatioNumber() + "P6");
                ratio.setXksdj("P6");
                ratioList.add(ratio);
                newRatioString = dataObject.getCustomRatioNumber() + "P6";

                NewRatio ratio1 = new NewRatio();
                ratio1.setXpebbh(dataObject.getCustomRatioNumber() + "P8");
                ratio1.setXksdj("P8");
                ratioList.add(ratio1);
                newRatioString = newRatioString + "," + dataObject.getCustomRatioNumber() + "P8";

                NewRatio ratio2 = new NewRatio();
                ratio2.setXpebbh(dataObject.getCustomRatioNumber() + "P10");
                ratio2.setXksdj("P10");
                ratioList.add(ratio2);
                newRatioString = newRatioString + "," + dataObject.getCustomRatioNumber() + "P10";

                NewRatio ratio3 = new NewRatio();
                ratio3.setXpebbh(dataObject.getCustomRatioNumber() + "P12");
                ratio3.setXksdj("P12");
                ratioList.add(ratio3);
                newRatioString = newRatioString + "," + dataObject.getCustomRatioNumber() + "P12";
            } else if ("P10".equals(dataObject.getKsdj())) {
                NewRatio ratio = new NewRatio();
                ratio.setXpebbh(dataObject.getCustomRatioNumber() + "P6");
                ratio.setXksdj("P6");
                ratioList.add(ratio);
                newRatioString = dataObject.getCustomRatioNumber() + "P6";

                NewRatio ratio1 = new NewRatio();
                ratio1.setXpebbh(dataObject.getCustomRatioNumber() + "P8");
                ratio1.setXksdj("P8");
                ratioList.add(ratio1);
                newRatioString = newRatioString + "," + dataObject.getCustomRatioNumber() + "P8";

                NewRatio ratio2 = new NewRatio();
                ratio2.setXpebbh(dataObject.getCustomRatioNumber() + "P10");
                ratio2.setXksdj("P10");
                ratioList.add(ratio2);
                newRatioString = newRatioString + "," + dataObject.getCustomRatioNumber() + "P10";

            } else if ("P8".equals(dataObject.getKsdj())) {
                NewRatio ratio = new NewRatio();
                ratio.setXpebbh(dataObject.getCustomRatioNumber() + "P6");
                ratio.setXksdj("P6");
                ratioList.add(ratio);
                newRatioString = dataObject.getCustomRatioNumber() + "P6";

                NewRatio ratio1 = new NewRatio();
                ratio1.setXpebbh(dataObject.getCustomRatioNumber() + "P8");
                ratio1.setXksdj("P8");
                ratioList.add(ratio1);
                newRatioString = newRatioString + "," + dataObject.getCustomRatioNumber() + "P8";

            } else if ("P6".equals(dataObject.getKsdj())) {
                NewRatio ratio = new NewRatio();
                ratio.setXpebbh(dataObject.getCustomRatioNumber() + "P6");
                ratio.setXksdj("P6");
                ratioList.add(ratio);
                newRatioString = dataObject.getCustomRatioNumber() + "P6";

            }

            JSONArray jsonArray = (JSONArray) JSON.toJSON(ratioList);
            mix.setNewRatio(jsonArray);
            mix.setNewRatioString(newRatioString);
        }

        if (dataObject.getSlump() != null && !dataObject.getSlump().isEmpty()) {
            String[] split = dataObject.getSlump().split("±");
            if (split != null) {
                MixProportionTld tld = new MixProportionTld();
                if (split[0] != null) {
                    tld.setQz(split[0]);
                }
                if (split[1] != null) {
                    tld.setHz(split[1]);
                }
                JSONObject jsonObject = JsonUtils.beanToObject(tld);
                mix.setProportionTld(jsonObject);
            }
        }

        mix.setPrintSjb(roundToOneDecimalPlace(dataObject.getSjb(), 1));
        mix.setPrintRz(roundToOneDecimalPlace(dataObject.getRz(), 0));
        mix.setPrintSl(roundToOneDecimalPlace(dataObject.getSl(), 0));
        mix.setPrintCl(roundToOneDecimalPlace(dataObject.getWjjcl(), 1));

        mix.setProductionSjb(roundToOneDecimalPlace(dataObject.getSjb(), 1));
        mix.setProductionRz(roundToOneDecimalPlace(dataObject.getRz(), 0));
        mix.setProductionSl(roundToOneDecimalPlace(dataObject.getSl(), 0));
        mix.setProductionCl(roundToOneDecimalPlace(dataObject.getWjjcl(), 1));

        mix.setProportionRemarks(dataObject.getRemark());


        MixProportionReport mixProportionReport = new MixProportionReport();

        //水泥
        MixProportionReport.BgxxInfo bgSnInfo = new MixProportionReport.BgxxInfo();
        bgSnInfo.setXhbgbh(dataObject.getSnbgbh());
        bgSnInfo.setCj(dataObject.getSncj());
        bgSnInfo.setCjjc(dataObject.getSncjjc());
        bgSnInfo.setGys(dataObject.getSngys());
        bgSnInfo.setGysjc(dataObject.getSngysjc());
        bgSnInfo.setDyyl(dataObject.getSnyl());
        bgSnInfo.setDyylb(dataObject.getSnylbl());
        bgSnInfo.setScyl(dataObject.getSnyl());
        bgSnInfo.setScylb(dataObject.getSnylbl());
        bgSnInfo.setClmc(dataObject.getSnmc());
        bgSnInfo.setWlmc(dataObject.getSnwlmc());
        bgSnInfo.setClgg(dataObject.getSngg());
        bgSnInfo.setWlgg(dataObject.getSnwlgg());
        bgSnInfo.setWllx(MaterialsEnum.CEMENT.getCode().toString());
        bgSnInfo.setBatch(dataObject.getSnph());
        bgSnInfo.setCertificateNo(dataObject.getSnbaz());
        mixProportionReport.setSn(bgSnInfo);

        //水
        MixProportionReport.BgxxInfo bgWaterInfo = new MixProportionReport.BgxxInfo();
        bgWaterInfo.setDyyl(dataObject.getWateryl());
        bgWaterInfo.setDyylb(dataObject.getWaterylbl());
        bgWaterInfo.setScyl(dataObject.getWateryl());
        bgWaterInfo.setScylb(dataObject.getWaterylbl());
        bgWaterInfo.setClmc(dataObject.getWatermc());
        bgWaterInfo.setWlmc(dataObject.getWatermc());
        bgWaterInfo.setClgg(dataObject.getWatergg());
        bgWaterInfo.setWlgg(dataObject.getWatergg());

        mixProportionReport.setWater(bgWaterInfo);

        //矿渣粉
        MixProportionReport.BgxxInfo bgKzfInfo = new MixProportionReport.BgxxInfo();
        bgKzfInfo.setXhbgbh(dataObject.getKzfbgbh());
        bgKzfInfo.setCj(dataObject.getKzfcj());
        bgKzfInfo.setCjjc(dataObject.getKzfcjjc());
        bgKzfInfo.setGys(dataObject.getKzfgys());
        bgKzfInfo.setGysjc(dataObject.getKzfgysjc());
        bgKzfInfo.setDyyl(dataObject.getKzfyl());
        bgKzfInfo.setDyylb(dataObject.getKzfylbl());
        bgKzfInfo.setScyl(dataObject.getKzfyl());
        bgKzfInfo.setScylb(dataObject.getKzfylbl());
        bgKzfInfo.setClmc(dataObject.getKzfmc());
        bgKzfInfo.setWlmc(dataObject.getKzfwlmc());
        bgKzfInfo.setClgg(dataObject.getKzfgg());
        bgKzfInfo.setWlgg(dataObject.getKzfwlgg());
        bgKzfInfo.setWllx(MaterialsEnum.SLAG.getCode().toString());
        bgKzfInfo.setBatch(dataObject.getKzfph());
        bgKzfInfo.setCertificateNo(dataObject.getKzfbaz());

        mixProportionReport.setKzf(bgKzfInfo);


        //粉煤灰
        MixProportionReport.BgxxInfo bgFmhInfo = new MixProportionReport.BgxxInfo();
        bgFmhInfo.setXhbgbh(dataObject.getFmhbgbh());
        bgFmhInfo.setCj(dataObject.getFmhcj());
        bgFmhInfo.setCjjc(dataObject.getFmhcjjc());
        bgFmhInfo.setGys(dataObject.getFmhgys());
        bgFmhInfo.setGysjc(dataObject.getFmhgysjc());
        bgFmhInfo.setDyyl(dataObject.getFmhyl());
        bgFmhInfo.setDyylb(dataObject.getFmhylbl());
        bgFmhInfo.setScyl(dataObject.getFmhyl());
        bgFmhInfo.setScylb(dataObject.getFmhylbl());
        bgFmhInfo.setClmc(dataObject.getFmhmc());
        bgFmhInfo.setWlmc(dataObject.getFmhwlmc());
        bgFmhInfo.setClgg(dataObject.getFmhgg());
        bgFmhInfo.setWlgg(dataObject.getFmhwlgg());
        bgFmhInfo.setWllx(MaterialsEnum.FLY.getCode().toString());
        bgFmhInfo.setBatch(dataObject.getFmhph());
        bgFmhInfo.setCertificateNo(dataObject.getFmhbaz());

        mixProportionReport.setFmh(bgFmhInfo);

        //粗骨料
        MixProportionReport.BgxxInfo bgCglInfo = new MixProportionReport.BgxxInfo();
        bgCglInfo.setXhbgbh(dataObject.getCglbgbh());
        bgCglInfo.setCj(dataObject.getCglcj());
        bgCglInfo.setCjjc(dataObject.getCglcjjc());
        bgCglInfo.setGys(dataObject.getCglgys());
        bgCglInfo.setGysjc(dataObject.getCglgysjc());
        bgCglInfo.setDyyl(dataObject.getCglyl());
        bgCglInfo.setDyylb(dataObject.getCglylbl());
        bgCglInfo.setScyl(dataObject.getCglyl());
        bgCglInfo.setScylb(dataObject.getCglylbl());
        bgCglInfo.setClmc(dataObject.getCglmc());
        bgCglInfo.setWlmc(dataObject.getCglwlmc());
        bgCglInfo.setClgg(dataObject.getCglgg());
        bgCglInfo.setWlgg(dataObject.getCglwlgg());
        bgCglInfo.setWllx(MaterialsEnum.COARSE.getCode().toString());
        bgCglInfo.setBatch(dataObject.getCglph());
        bgCglInfo.setCertificateNo(dataObject.getCglbaz());

        mixProportionReport.setCgl(bgCglInfo);

        //细骨料
        MixProportionReport.BgxxInfo bgXglInfo = new MixProportionReport.BgxxInfo();
        bgXglInfo.setXhbgbh(dataObject.getXglbgbh());
        bgXglInfo.setCj(dataObject.getXglcj());
        bgXglInfo.setCjjc(dataObject.getXglcjjc());
        bgXglInfo.setGys(dataObject.getXglgys());
        bgXglInfo.setGysjc(dataObject.getXglgysjc());
        bgXglInfo.setDyyl(dataObject.getXglyl());
        bgXglInfo.setDyylb(dataObject.getXglylbl());
        bgXglInfo.setScyl(dataObject.getXglyl());
        bgXglInfo.setScylb(dataObject.getXglylbl());
        bgXglInfo.setClmc(dataObject.getXglmc());
        bgXglInfo.setWlmc(dataObject.getXglwlmc());
        bgXglInfo.setClgg(dataObject.getXglgg());
        bgXglInfo.setWlgg(dataObject.getXglwlgg());
        bgXglInfo.setWllx(MaterialsEnum.FINE.getCode().toString());
        bgXglInfo.setBatch(dataObject.getXglph());
        bgXglInfo.setCertificateNo(dataObject.getXglbaz());

        mixProportionReport.setXgl(bgXglInfo);


        //外加剂1
        MixProportionReport.BgxxInfo bgWjj1Info = new MixProportionReport.BgxxInfo();
        bgWjj1Info.setXhbgbh(dataObject.getWjj1bgbh());
        bgWjj1Info.setCj(dataObject.getWjj1cj());
        bgWjj1Info.setCjjc(dataObject.getWjj1cjjc());
        bgWjj1Info.setGys(dataObject.getWjj1gys());
        bgWjj1Info.setGysjc(dataObject.getWjj1gysjc());
        bgWjj1Info.setDyyl(dataObject.getWjj1yl());
        bgWjj1Info.setDyylb(dataObject.getWjj1ylbl());
        bgWjj1Info.setScyl(dataObject.getWjj1yl());
        bgWjj1Info.setScylb(dataObject.getWjj1ylbl());
        bgWjj1Info.setClmc(dataObject.getWjj1mc());
        bgWjj1Info.setWlmc(dataObject.getWjj1wlmc());
        bgWjj1Info.setClgg(dataObject.getWjj1gg());
        bgWjj1Info.setWlgg(dataObject.getWjj1wlgg());
        bgWjj1Info.setWllx(MaterialsEnum.ADMIXTURE.getCode().toString());
        bgWjj1Info.setBatch(dataObject.getWjj1ph());
        bgWjj1Info.setCertificateNo(dataObject.getWjj1baz());

        mixProportionReport.setWjj1(bgWjj1Info);


        //外加剂2
        MixProportionReport.BgxxInfo bgWjj2Info = new MixProportionReport.BgxxInfo();
        bgWjj2Info.setXhbgbh(dataObject.getWjj2bgbh());
        bgWjj2Info.setCj(dataObject.getWjj2cj());
        bgWjj2Info.setCjjc(dataObject.getWjj2cjjc());
        bgWjj2Info.setGys(dataObject.getWjj2gys());
        bgWjj2Info.setGysjc(dataObject.getWjj2gysjc());
        bgWjj2Info.setDyyl(dataObject.getWjj2yl());
        bgWjj2Info.setDyylb(dataObject.getWjj2ylbl());
        bgWjj2Info.setScyl(dataObject.getWjj2yl());
        bgWjj2Info.setScylb(dataObject.getWjj2ylbl());
        bgWjj2Info.setClmc(dataObject.getWjj2mc());
        bgWjj2Info.setWlmc(dataObject.getWjj2wlmc());
        bgWjj2Info.setClgg(dataObject.getWjj2gg());
        bgWjj2Info.setWlgg(dataObject.getWjj2wlgg());
        bgWjj2Info.setWllx(MaterialsEnum.ADMIXTURE.getCode().toString());
        bgWjj2Info.setBatch(dataObject.getWjj2ph());
        bgWjj2Info.setCertificateNo(dataObject.getWjj2baz());

        mixProportionReport.setWjj2(bgWjj2Info);

        JSONObject jsonObject = JsonUtils.beanToObject(mixProportionReport);
        mix.setProportionMaterial(jsonObject);

    }


    private String roundToOneDecimalPlace(String valueStr, int scale) {
        try {
            // 向上取整（RoundingMode.CEILING）
            BigDecimal ceilBd = new BigDecimal(valueStr)
                    .setScale(scale, RoundingMode.CEILING);
            if (scale == 0) {
                return String.valueOf(ceilBd.intValue());
            }
            return String.valueOf(ceilBd.doubleValue());
        } catch (NumberFormatException e) {
            // 如果字符串无法转换为数值，返回原始字符串
            return valueStr;
        }
    }


    /**
     * 根据服务类型获取磁盘路径
     * 默认是windows磁盘路径
     *
     * @return
     */
    public String getPathName() {
        String operSystem = MacTools.getOperSystem();
        if (Arrays.stream(BaseParams.MAC_LIST).parallel().anyMatch(operSystem::contains)) {
            return ADDRESS_MAC;
        } else if (Arrays.stream(BaseParams.LINUX_LIST).parallel().anyMatch(operSystem::contains)) {
            return ADDRESS_LINUX;
        }
        return ADDRESS_WINDOWS;
    }

    //新增品控 和  协会
    private void setLaboratory(MixProportion mix, ExcelProportionDataObject dataObject) {
        //协会配合比对象
        DataHntPhb dataHntPhb = new DataHntPhb();

        dataHntPhb.setMpno(dataObject.getCustomRatioNumber());//配合比编号
        dataHntPhb.setMpdesignStrength(dataObject.getSjqd());//强度等级

        dataHntPhb.setMpdesignSlump(ConvertUtils.getTldUnit(dataObject.getSlump()));//设计塌落度

        dataHntPhb.setMpbreakingStrength(dataObject.getKzqd());//抗折强度
        dataHntPhb.setMpwaterProofing(dataObject.getKsdj());//抗渗等级
        dataHntPhb.setMpdesignJudgeBy("");//设计依据
        dataHntPhb.setMpdesignRemark(dataObject.getRemark());//备注
        dataHntPhb.setIsChecked((long) 1);//默认为1

        //水灰比

        if (dataObject.getWateryl() != null) {
            Double sjb = 0d;
            double sum = 0d;
            if (dataObject.getSnyl() != null) {
                sum += dataObject.getSnyl();
            }
            if (dataObject.getKzfyl() != null) {
                sum += dataObject.getKzfyl();
            }
            if (dataObject.getFmhyl() != null) {
                sum += dataObject.getFmhyl();
            }

            sjb = (dataObject.getWateryl() / sum * 100) / 1000;
            sjb = Math.round(sjb * 100) / 100.0;
            dataHntPhb.setFiWaterCementRatio(sjb.toString());
        }


        //定死T0738
        dataHntPhb.setTrialMan("T0738");

        String uploadFlag = UploadFlagUtils.CtoGB_Num("0000000000", "z", new Date(), null);
        dataHntPhb.setUploadFlag(uploadFlag);


        //打印用量传值到 协会
        dataHntPhb.setFiC(NullUtils.ifNull(dataObject.getSnyl()));//水泥用量
        dataHntPhb.setFiF(NullUtils.ifNull(dataObject.getFmhyl()));//粉煤灰用量
        dataHntPhb.setFiZ(NullUtils.ifNull(dataObject.getKzfyl()));//矿渣粉用量
        dataHntPhb.setFiW(NullUtils.ifNull(dataObject.getWateryl()));//水用量
        dataHntPhb.setFiS(NullUtils.ifNull(dataObject.getXglyl()));//细骨料用量
        dataHntPhb.setFiG(NullUtils.ifNull(dataObject.getCglyl()));//粗骨料用量
        dataHntPhb.setFiAd(NullUtils.ifNull(dataObject.getWjj1yl()));//外加剂1用量
        dataHntPhb.setFiAd2(NullUtils.ifNull(dataObject.getWjj2yl()));//外加剂2用量

        if (dataObject.getSnyl() != null) {
            dataHntPhb.setFiRatioC("1");//水泥用量比例

            if (dataObject.getFmhyl() != null) {
                //用量比例 等于 本身 除以水泥用量  保留两位小数
                Double result = dataObject.getFmhyl() / dataObject.getSnyl();
                result = Math.round(result * 100) / 100.0;
                dataHntPhb.setFiRatioF(result.toString());//粉煤灰用量比例
            }
            if (dataObject.getKzfyl() != null) {
                Double result = dataObject.getKzfyl() / dataObject.getSnyl();
                result = Math.round(result * 100) / 100.0;
                dataHntPhb.setFiRatioZ(result.toString());//矿渣粉用量比例
            }
            if (dataObject.getWateryl() != null) {
                Double result = dataObject.getWateryl() / dataObject.getSnyl();
                result = Math.round(result * 100) / 100.0;
                dataHntPhb.setFiRatioW(result.toString());//水用量比例
            }
            if (dataObject.getXglyl() != null) {
                Double result = dataObject.getXglyl() / dataObject.getSnyl();
                result = Math.round(result * 100) / 100.0;
                dataHntPhb.setFiRatioS(result.toString());//细骨料用量比例
            }
            if (dataObject.getCglyl() != null) {
                Double result = dataObject.getCglyl() / dataObject.getSnyl();
                result = Math.round(result * 100) / 100.0;
                dataHntPhb.setFiRatioG(result.toString());//粗骨料用量比例
            }
            if (dataObject.getWjj1yl() != null) {
                Double result = dataObject.getWjj1yl() / dataObject.getSnyl();
                result = Math.round(result * 100) / 100.0;
                dataHntPhb.setFiRatioAd(result.toString());//外加剂1用量比例
            }
            if (dataObject.getWjj2yl() != null) {
                Double result = dataObject.getWjj2yl() / dataObject.getSnyl();
                result = Math.round(result * 100) / 100.0;
                dataHntPhb.setFiRatioAd2(result.toString());//外加剂2用量比例
            }
        }


        //报告编号
        dataHntPhb.setReportIdC(dataObject.getSnbgbh());
        dataHntPhb.setReportIdF(dataObject.getFmhbgbh());
        dataHntPhb.setReportIdZ(dataObject.getKzfbgbh());
        dataHntPhb.setReportIdS(dataObject.getXglbgbh());
        dataHntPhb.setReportIdG(dataObject.getCglbgbh());
        dataHntPhb.setReportIdAd(dataObject.getWjj1bgbh());
        dataHntPhb.setReportIdAd2(dataObject.getWjj2bgbh());

        //厂家
        dataHntPhb.setHeadStreamC(dataObject.getSncj());
        dataHntPhb.setHeadStreamF(dataObject.getFmhcj());
        dataHntPhb.setHeadStreamZ(dataObject.getKzfcj());
        dataHntPhb.setHeadStreamS(dataObject.getXglcj());
        dataHntPhb.setHeadStreamAd(dataObject.getWjj1cj());
        dataHntPhb.setHeadStreamAd2(dataObject.getWjj2cj());


        //查询原材料名称 规格 信息
        List<String> namesList = new ArrayList<>();
        if (dataObject.getSnmc() != null) {
            namesList.add(dataObject.getSnmc());
        }
        if (dataObject.getFmhmc() != null) {
            namesList.add(dataObject.getFmhmc());
        }
        if (dataObject.getKzfmc() != null) {
            namesList.add(dataObject.getKzfmc());
        }
        if (dataObject.getCglmc() != null) {
            namesList.add(dataObject.getCglmc());
        }
        if (dataObject.getXglmc() != null) {
            namesList.add(dataObject.getXglmc());
        }
        if (dataObject.getWjj1mc() != null) {
            namesList.add(dataObject.getWjj1mc());
        }
        if (dataObject.getWjj2mc() != null) {
            namesList.add(dataObject.getWjj2mc());
        }


        List<String> gradeNamesList = new ArrayList<>();
        if (dataObject.getSngg() != null) {
            gradeNamesList.add(dataObject.getSngg());
        }
        if (dataObject.getKzfgg() != null) {
            gradeNamesList.add(dataObject.getKzfgg());
        }
        if (dataObject.getWjj1gg() != null) {
            gradeNamesList.add(dataObject.getWjj1gg());
        }
        if (dataObject.getWjj2gg() != null) {
            gradeNamesList.add(dataObject.getWjj2gg());
        }
        if (dataObject.getFmhgg() != null) {
            gradeNamesList.add(dataObject.getFmhgg());
        }

        List<Map<String, Object>> gradeIds = new ArrayList<>();

        if (gradeNamesList.size() != 0 && namesList.size() != 0) {
            gradeIds = m_uploadLaboratoryMapper.findItemGradeByGradeName(gradeNamesList, namesList);
        }


        List<String> specNamesList = new ArrayList<>();
        if (dataObject.getCglgg() != null) {
            specNamesList.add(dataObject.getCglgg());
        }
        if (dataObject.getXglgg() != null) {
            specNamesList.add(dataObject.getXglgg());
        }
        if (dataObject.getFmhgg2() != null) {
            specNamesList.add(dataObject.getFmhgg2());
        }

        List<Map<String, Object>> specIds = new ArrayList<>();

        if (specNamesList.size() != 0 && namesList.size() != 0) {
            specIds = m_uploadLaboratoryMapper.findItemSpecBySpecName(specNamesList, namesList);
        }


        for (Map<String, Object> map : gradeIds) {
            if (map.get("GradeName") != null && map.get("SampleName") != null) {
                //水泥
                if (StringUtils.isNotBlank(dataObject.getSnmc()) && StringUtils.isNotBlank(dataObject.getSngg())) {
                    if (map.get("GradeName").toString().equals(dataObject.getSngg()) && map.get("SampleName").equals(dataObject.getSnmc())) {
                        if (map.get("SampleID") != null) {
                            dataHntPhb.setSampleIdC(Long.parseLong(map.get("SampleID").toString()));
                        }
                        if (map.get("GradeID") != null) {
                            dataHntPhb.setGradeIdC(Long.parseLong(map.get("GradeID").toString()));
                        }
                    }
                }


                //矿渣粉
                if (StringUtils.isNotBlank(dataObject.getKzfmc()) && StringUtils.isNotBlank(dataObject.getKzfgg())) {
                    if (map.get("GradeName").toString().equals(dataObject.getKzfgg()) && map.get("SampleName").equals(dataObject.getKzfmc())) {
                        if (map.get("SampleID") != null) {
                            dataHntPhb.setSampleIdZ(Long.parseLong(map.get("SampleID").toString()));
                        }
                        if (map.get("GradeID") != null) {
                            dataHntPhb.setGradeIdZ(Long.parseLong(map.get("GradeID").toString()));
                        }
                    }
                }


                //外加剂1
                if (StringUtils.isNotBlank(dataObject.getWjj1mc()) && StringUtils.isNotBlank(dataObject.getWjj1gg())) {
                    if (map.get("GradeName").toString().equals(dataObject.getWjj1gg()) && map.get("SampleName").equals(dataObject.getWjj1mc())) {
                        if (map.get("SampleID") != null) {
                            dataHntPhb.setSampleIdAd(Long.parseLong(map.get("SampleID").toString()));
                        }
                        if (map.get("GradeID") != null) {
                            dataHntPhb.setGradeIdAd(Long.parseLong(map.get("GradeID").toString()));
                        }
                    }
                }

                //外加剂2
                if (StringUtils.isNotBlank(dataObject.getWjj2mc()) && StringUtils.isNotBlank(dataObject.getWjj2gg())) {
                    if (map.get("GradeName").toString().equals(dataObject.getWjj2gg()) && map.get("SampleName").equals(dataObject.getWjj2mc())) {
                        if (map.get("SampleID") != null) {
                            dataHntPhb.setSampleIdAd2(Long.parseLong(map.get("SampleID").toString()));
                        }
                        if (map.get("GradeID") != null) {
                            dataHntPhb.setGradeIdAd2(Long.parseLong(map.get("GradeID").toString()));
                        }
                    }
                }

                //粉煤灰
                if (StringUtils.isNotBlank(dataObject.getFmhmc()) && StringUtils.isNotBlank(dataObject.getFmhgg())) {
                    if (map.get("GradeName").toString().equals(dataObject.getFmhgg()) && map.get("SampleName").equals(dataObject.getFmhmc())) {
                        if (map.get("SampleID") != null) {
                            dataHntPhb.setSampleIdF(Long.parseLong(map.get("SampleID").toString()));
                        }
                        if (map.get("GradeID") != null) {
                            dataHntPhb.setGradeIdF(Long.parseLong(map.get("GradeID").toString()));
                        }
                    }
                }

            }
        }


        for (Map<String, Object> map : specIds) {
            if (map.get("SpecName") != null && map.get("SampleName") != null) {
                //粉煤灰
                if (StringUtils.isNotBlank(dataObject.getFmhmc()) && StringUtils.isNotBlank(dataObject.getFmhgg2())) {
                    if (map.get("SpecName").toString().equals(dataObject.getFmhgg2()) && map.get("SampleName").equals(dataObject.getFmhmc())) {
                        if (map.get("SpecID") != null) {
                            dataHntPhb.setSpecIdF(Long.parseLong(map.get("SampleID").toString()));
                        }

                    }
                }

                //粗骨料
                if (StringUtils.isNotBlank(dataObject.getCglmc()) && StringUtils.isNotBlank(dataObject.getCglgg())) {
                    if (map.get("SpecName").toString().equals(dataObject.getCglgg()) && map.get("SampleName").equals(dataObject.getCglmc())) {
                        if (map.get("SpecID") != null) {
                            dataHntPhb.setSpecIdG(Long.parseLong(map.get("SampleID").toString()));
                        }

                    }
                }

                //细骨料
                if (StringUtils.isNotBlank(dataObject.getXglmc()) && StringUtils.isNotBlank(dataObject.getXglgg())) {
                    if (map.get("SpecName").toString().equals(dataObject.getXglgg()) && map.get("SampleName").equals(dataObject.getXglmc())) {
                        if (map.get("SpecID") != null) {
                            dataHntPhb.setSpecIdS(Long.parseLong(map.get("SampleID").toString()));
                        }

                    }
                }
            }
        }

      /*  //新增
        dataHntPhbMapper.addDATA_HNTPHB(dataHntPhb);

        //新增品控
        setMixProportion(mix, dataHntPhb, dataObject);*/

    }

    //修改
    private void setLaboratoryNew(MixProportion mix, ExcelProportionDataObject dataObject, DataHntPhb dataHntPhb) {


        //细骨料粗骨料规格有值的不处理
        if (dataHntPhb != null && dataHntPhb.getSampleIdS() != null && dataHntPhb.getSampleIdG() != null) {
            return;
        }


        //查询原材料名称 规格 信息（粉煤灰 粗骨料 细骨料）
        List<String> namesList = new ArrayList<>();
        if (dataObject.getFmhmc() != null) {
            namesList.add(dataObject.getFmhmc());
        }
        if (dataObject.getCglmc() != null) {
            namesList.add(dataObject.getCglmc());
        }
        if (dataObject.getXglmc() != null) {
            namesList.add(dataObject.getXglmc());
        }


        List<String> gradeNamesList = new ArrayList<>();

        if (dataObject.getFmhgg() != null) {
            gradeNamesList.add(dataObject.getFmhgg());
        }

        List<Map<String, Object>> gradeIds = new ArrayList<>();

        if (gradeNamesList.size() != 0 && namesList.size() != 0) {
            gradeIds = m_uploadLaboratoryMapper.findItemGradeByGradeName(gradeNamesList, namesList);
        }


        List<String> specNamesList = new ArrayList<>();
        if (dataObject.getCglgg() != null) {
            specNamesList.add(dataObject.getCglgg());
        }
        if (dataObject.getXglgg() != null) {
            specNamesList.add(dataObject.getXglgg());
        }
        if (dataObject.getFmhgg2() != null) {
            specNamesList.add(dataObject.getFmhgg2());
        }

        List<Map<String, Object>> specIds = new ArrayList<>();

        if (specNamesList.size() != 0 && namesList.size() != 0) {
            specIds = m_uploadLaboratoryMapper.findItemSpecBySpecName(specNamesList, namesList);
        }


        for (Map<String, Object> map : gradeIds) {
            if (map.get("GradeName") != null && map.get("SampleName") != null) {

                //粉煤灰
                if (StringUtils.isNotBlank(dataObject.getFmhmc()) && StringUtils.isNotBlank(dataObject.getFmhgg())) {
                    if (map.get("GradeName").toString().equals(dataObject.getFmhgg()) && map.get("SampleName").equals(dataObject.getFmhmc())) {
                        if (map.get("SampleID") != null) {
                            dataHntPhb.setSampleIdF(Long.parseLong(map.get("SampleID").toString()));
                        }
                        if (map.get("GradeID") != null) {
                            dataHntPhb.setGradeIdF(Long.parseLong(map.get("GradeID").toString()));
                        }
                    }
                }

            }
        }


        for (Map<String, Object> map : specIds) {
            if (map.get("SpecName") != null && map.get("SampleName") != null) {
                //粉煤灰
                if (StringUtils.isNotBlank(dataObject.getFmhmc()) && StringUtils.isNotBlank(dataObject.getFmhgg2())) {
                    if (map.get("SpecName").toString().equals(dataObject.getFmhgg2()) && map.get("SampleName").equals(dataObject.getFmhmc())) {
                        if (map.get("SpecID") != null) {
                            dataHntPhb.setSpecIdF(Long.parseLong(map.get("SpecID").toString()));
                        }

                    }
                }

                //粗骨料
                if (StringUtils.isNotBlank(dataObject.getCglmc()) && StringUtils.isNotBlank(dataObject.getCglgg())) {
                    if (map.get("SpecName").toString().equals(dataObject.getCglgg()) && map.get("SampleName").equals(dataObject.getCglmc())) {
                        if (map.get("SampleID") != null) {
                            dataHntPhb.setSampleIdG(Long.parseLong(map.get("SampleID").toString()));
                        }
                        if (map.get("SpecID") != null) {
                            dataHntPhb.setSpecIdG(Long.parseLong(map.get("SpecID").toString()));
                        }

                    }
                }

                //细骨料
                if (StringUtils.isNotBlank(dataObject.getXglmc()) && StringUtils.isNotBlank(dataObject.getXglgg())) {
                    if (map.get("SpecName").toString().equals(dataObject.getXglgg()) && map.get("SampleName").equals(dataObject.getXglmc())) {
                        if (map.get("SampleID") != null) {
                            dataHntPhb.setSampleIdS(Long.parseLong(map.get("SampleID").toString()));
                        }
                        if (map.get("SpecID") != null) {
                            dataHntPhb.setSpecIdS(Long.parseLong(map.get("SpecID").toString()));
                        }

                    }
                }
            }
        }


        //修改品控
        setUpdateMixProportion(mix, dataHntPhb, dataObject);

        //修改协会配合比
        dataHntPhbMapper.updateDATA_HNTPHB(dataHntPhb);

    }

    //赋值品控配合比对象
    private void setMixProportion(MixProportion mix, DataHntPhb dataHntPhb, ExcelProportionDataObject dataObject) {

        //定死默认创建人为 id 配置文件 的
        mix.setUpdater(createrId == null ? null : Long.parseLong(createrId)).setUpdateTime(new Date()).setCreater(createrId == null ? null : Long.parseLong(createrId))
                .setCreateTime(new Date())
                .setIsDel(0);
        mix.setProportionPhb(dataHntPhb.getMpno());
        mix.setProportionSjyj(dataHntPhb.getMpdesignJudgeBy());
        mix.setProportionQddj(dataHntPhb.getMpdesignStrength());
        mix.setProportionKzqd(dataHntPhb.getMpbreakingStrength());
        mix.setProportionKsdj(dataHntPhb.getMpwaterProofing());
        mix.setProportionQllz("");//强氯离子

        if (dataHntPhb.getMpdesignSlump() != null && !dataHntPhb.getMpdesignSlump().isEmpty()) {
            String[] split = dataHntPhb.getMpdesignSlump().split("±");
            if (split != null) {
                MixProportionTld tld = new MixProportionTld();
                if (split[0] != null) {
                    tld.setQz(split[0]);
                }
                if (split[1] != null) {
                    tld.setHz(split[1]);
                }
                JSONObject jsonObject = JsonUtils.beanToObject(tld);
                mix.setProportionTld(jsonObject);
            }
        }

        mix.setPrintSjb(dataHntPhb.getFiWaterCementRatio());
        mix.setProportionRemarks(dataHntPhb.getMpdesignRemark());


        MixProportionReport mixProportionReport = new MixProportionReport();

        //查询原材料名称 规格 信息
        List<String> sampleIdList = new ArrayList<>();
        if (dataHntPhb.getSampleIdC() != null) {
            sampleIdList.add(dataHntPhb.getSampleIdC().toString());
        }
        if (dataHntPhb.getSampleIdF() != null) {
            sampleIdList.add(dataHntPhb.getSampleIdF().toString());
        }
        if (dataHntPhb.getSampleIdZ() != null) {
            sampleIdList.add(dataHntPhb.getSampleIdZ().toString());
        }
        if (dataHntPhb.getSampleIdS() != null) {
            sampleIdList.add(dataHntPhb.getSampleIdS().toString());
        }
        if (dataHntPhb.getSampleIdG() != null) {
            sampleIdList.add(dataHntPhb.getSampleIdG().toString());
        }
        if (dataHntPhb.getSampleIdAd() != null) {
            sampleIdList.add(dataHntPhb.getSampleIdAd().toString());
        }
        if (dataHntPhb.getSampleIdAd2() != null) {
            sampleIdList.add(dataHntPhb.getSampleIdAd2().toString());
        }

        //材料名称
        List<Map<String, Object>> sampleIDs = new ArrayList<>();
        if (sampleIdList.size() != 0) {
            sampleIDs = m_uploadLaboratoryMapper.findItemSampleBySampleID(sampleIdList);
        }


        List<String> gradeIdList = new ArrayList<>();
        if (dataHntPhb.getGradeIdC() != null) {
            gradeIdList.add(dataHntPhb.getGradeIdC().toString());
        }
        if (dataHntPhb.getGradeIdF() != null) {
            gradeIdList.add(dataHntPhb.getGradeIdF().toString());
        }
        if (dataHntPhb.getGradeIdS() != null) {
            gradeIdList.add(dataHntPhb.getGradeIdS().toString());
        }
        if (dataHntPhb.getGradeIdZ() != null) {
            gradeIdList.add(dataHntPhb.getGradeIdZ().toString());
        }
        if (dataHntPhb.getGradeIdG() != null) {
            gradeIdList.add(dataHntPhb.getGradeIdG().toString());
        }
        if (dataHntPhb.getGradeIdAd() != null) {
            gradeIdList.add(dataHntPhb.getGradeIdAd().toString());
        }
        if (dataHntPhb.getGradeIdAd2() != null) {
            gradeIdList.add(dataHntPhb.getGradeIdAd2().toString());
        }
        List<Map<String, Object>> gradeIds = new ArrayList<>();

        if (gradeIdList.size() != 0) {
            gradeIds = m_uploadLaboratoryMapper.findItemGradeByGradeId(gradeIdList);
        }


        List<String> specIdList = new ArrayList<>();
        if (dataHntPhb.getSpecIdC() != null) {
            specIdList.add(dataHntPhb.getSpecIdC().toString());
        }
        if (dataHntPhb.getSpecIdF() != null) {
            specIdList.add(dataHntPhb.getSpecIdF().toString());
        }
        if (dataHntPhb.getSpecIdZ() != null) {
            specIdList.add(dataHntPhb.getSpecIdZ().toString());
        }
        if (dataHntPhb.getSpecIdG() != null) {
            specIdList.add(dataHntPhb.getSpecIdG().toString());
        }
        if (dataHntPhb.getSpecIdS() != null) {
            specIdList.add(dataHntPhb.getSpecIdS().toString());
        }
        if (dataHntPhb.getSpecIdAd() != null) {
            specIdList.add(dataHntPhb.getSpecIdAd().toString());
        }
        if (dataHntPhb.getSpecIdAd2() != null) {
            specIdList.add(dataHntPhb.getSpecIdAd2().toString());
        }
        List<Map<String, Object>> specIds = new ArrayList<>();

        if (specIdList.size() != 0) {
            specIds = m_uploadLaboratoryMapper.findItemSpecBySpecId(specIdList);
        }

        List<String> reports = new ArrayList<>();
        //报告编号
        if (StringUtils.isNotBlank(dataHntPhb.getReportIdC())) {
            reports.add(dataHntPhb.getReportIdC());
        }
        if (StringUtils.isNotBlank(dataHntPhb.getReportIdF())) {
            reports.add(dataHntPhb.getReportIdF());
        }
        if (StringUtils.isNotBlank(dataHntPhb.getReportIdZ())) {
            reports.add(dataHntPhb.getReportIdZ());
        }
        if (StringUtils.isNotBlank(dataHntPhb.getReportIdS())) {
            reports.add(dataHntPhb.getReportIdS());
        }
        if (StringUtils.isNotBlank(dataHntPhb.getReportIdG())) {
            reports.add(dataHntPhb.getReportIdG());
        }
        if (StringUtils.isNotBlank(dataHntPhb.getReportIdAd())) {
            reports.add(dataHntPhb.getReportIdAd());
        }
        if (StringUtils.isNotBlank(dataHntPhb.getReportIdAd2())) {
            reports.add(dataHntPhb.getReportIdAd2());
        }

        List<ImportList> importList = new ArrayList<>();
        if (reports.size() != 0) {
            importList = importListMapper.findImportListByReportId(reports);
        }


        //容重
        Double scrz = 0d;
        Double dyrz = 0d;

        //水胶比
        Double scsjb = 0d;
        Double dysjb = 0d;

        //砂率
        Double scsl = 0d;
        Double dysl = 0d;

        //外加剂掺量
        Double sccl = 0d;
        Double dycl = 0d;


        //水泥
        if (dataHntPhb.getReportIdC() != null && !dataHntPhb.getReportIdC().isEmpty()) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setXhbgbh(dataHntPhb.getReportIdC());
            bgxxInfo.setCj(dataHntPhb.getHeadStreamC());
            //默认协会的用量 为打印用量
            bgxxInfo.setDyyl(dataHntPhb.getFiC());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioC());

            if (StringUtils.isNotBlank(dataHntPhb.getFiC())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiC());
            }


            //默认excel的用量为生产用量
            if (dataObject.getSnyl() != null) {
                bgxxInfo.setScyl(dataObject.getSnyl().toString());
                bgxxInfo.setScylb("1");

                scrz += dataObject.getSnyl();
            }
            //赋值材料名称
            if (dataHntPhb.getSampleIdC() != null) {
                for (Map<String, Object> map : sampleIDs) {
                    if (map.get("SampleID") != null && dataHntPhb.getSampleIdC().toString().equals(map.get("SampleID").toString())) {
                        bgxxInfo.setClmc(map.get("SampleName").toString());
                        bgxxInfo.setWlmc(map.get("SampleName").toString());
                    }
                }
            }
            //赋值材料规格
            if (dataHntPhb.getGradeIdC() != null) {
                for (Map<String, Object> map : gradeIds) {
                    if (map.get("GradeID") != null && dataHntPhb.getGradeIdC().toString().equals(map.get("GradeID").toString())) {
                        bgxxInfo.setClgg(map.get("GradeName").toString());
                        bgxxInfo.setWlgg(map.get("GradeName").toString());
                    }
                }
            }

            //赋值备案证等信息
            if (dataHntPhb.getReportIdC() != null) {
                for (ImportList map : importList) {
                    if (map.getReportId() != null && dataHntPhb.getReportIdC().equals(map.getReportId())) {
                        if (map.getGradeId() != null) {
                            bgxxInfo.setBatch(map.getGradeId());
                        }
                        if (map.getRecordCertificate() != null) {
                            bgxxInfo.setCertificateNo(map.getRecordCertificate());
                        }
                    }
                }
            }

            mixProportionReport.setSn(bgxxInfo);
        }


        //水
        if (dataHntPhb.getFiW() != null) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setClmc("水");
            bgxxInfo.setWlmc("水");
            bgxxInfo.setClgg("清水");
            bgxxInfo.setWlgg("清水");
            bgxxInfo.setDyyl(dataHntPhb.getFiW());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioW());

            if (StringUtils.isNotBlank(dataHntPhb.getFiW())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiW());

                //水胶比公式：(水 / （水泥+矿粉+粉煤灰）生产用量)*100)/1000
                double sum = 0d;
                if (dataObject.getSnyl() != null) {
                    sum += dataObject.getSnyl();
                }
                if (dataObject.getKzfyl() != null) {
                    sum += dataObject.getKzfyl();
                }
                if (dataObject.getFmhyl() != null) {
                    sum += dataObject.getFmhyl();
                }

                dysjb = (Double.parseDouble(dataHntPhb.getFiW()) / sum * 100) / 1000;
            }

            //默认excel的用量为生产用量
            if (dataObject.getWateryl() != null) {
                scrz += dataObject.getWateryl();
                bgxxInfo.setScyl(dataObject.getWateryl().toString());
                if (dataObject.getSnyl() != null) {
                    //用量比例 等于 本身 除以水泥用量  保留两位小数
                    double result = dataObject.getWateryl() / dataObject.getSnyl();
                    result = Math.round(result * 100) / 100.0;
                    bgxxInfo.setScylb(String.valueOf(result));
                }

                double sum = 0d;
                if (dataObject.getSnyl() != null) {
                    sum += dataObject.getSnyl();
                }
                if (dataObject.getKzfyl() != null) {
                    sum += dataObject.getKzfyl();
                }
                if (dataObject.getFmhyl() != null) {
                    sum += dataObject.getFmhyl();
                }

                scsjb = (dataObject.getWateryl() / sum * 100) / 1000;

            }


            mixProportionReport.setWater(bgxxInfo);
        }

        //粉煤灰
        if (dataHntPhb.getReportIdF() != null && !dataHntPhb.getReportIdF().isEmpty()) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setXhbgbh(dataHntPhb.getReportIdF());
            bgxxInfo.setCj(dataHntPhb.getHeadStreamF());
            //默认协会的用量 为打印用量
            bgxxInfo.setDyyl(dataHntPhb.getFiF());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioF());

            if (StringUtils.isNotBlank(dataHntPhb.getFiF())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiF());
            }


            //赋值备案证等信息
            if (dataHntPhb.getReportIdF() != null) {
                for (ImportList map : importList) {
                    if (map.getReportId() != null && dataHntPhb.getReportIdF().equals(map.getReportId())) {
                        if (map.getGradeId() != null) {
                            bgxxInfo.setBatch(map.getGradeId());
                        }
                        if (map.getRecordCertificate() != null) {
                            bgxxInfo.setCertificateNo(map.getRecordCertificate());
                        }
                    }
                }
            }

            //默认excel的用量为生产用量
            if (dataObject.getFmhyl() != null) {
                scrz += dataObject.getFmhyl();
                bgxxInfo.setScyl(dataObject.getFmhyl().toString());
                if (dataObject.getSnyl() != null) {
                    //用量比例 等于 本身 除以水泥用量  保留两位小数
                    double result = dataObject.getFmhyl() / dataObject.getSnyl();
                    result = Math.round(result * 100) / 100.0;
                    bgxxInfo.setScylb(String.valueOf(result));
                }

            }
            //赋值材料名称
            if (dataHntPhb.getSampleIdF() != null) {
                for (Map<String, Object> map : sampleIDs) {
                    if (map.get("SampleID") != null && dataHntPhb.getSampleIdF().toString().equals(map.get("SampleID").toString())) {
                        bgxxInfo.setClmc(map.get("SampleName").toString());
                        bgxxInfo.setWlmc(map.get("SampleName").toString());
                    }
                }
            }
            //赋值材料规格
            if (dataHntPhb.getGradeIdF() != null) {
                String name = "";
                for (Map<String, Object> map : gradeIds) {
                    if (map.get("GradeID") != null && dataHntPhb.getGradeIdF().toString().toString().equals(map.get("GradeID").toString())) {
                        name = map.get("GradeName").toString();
                    }
                }

                if (dataHntPhb.getSpecIdF() != null) {
                    for (Map<String, Object> map : specIds) {
                        if (map.get("SpecID") != null && dataHntPhb.getSpecIdF().toString().equals(map.get("SpecID").toString())) {
                            name = map.get("SpecName").toString() + name;
                        }
                    }
                }

                bgxxInfo.setClgg(name);
                bgxxInfo.setWlgg(name);
            }

            mixProportionReport.setFmh(bgxxInfo);
        }


        //矿渣粉
        if (dataHntPhb.getReportIdZ() != null && !dataHntPhb.getReportIdZ().isEmpty()) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setXhbgbh(dataHntPhb.getReportIdZ());
            bgxxInfo.setCj(dataHntPhb.getHeadStreamZ());
            //默认协会的用量 为打印用量
            bgxxInfo.setDyyl(dataHntPhb.getFiZ());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioZ());

            if (StringUtils.isNotBlank(dataHntPhb.getFiZ())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiZ());
            }

            //赋值备案证等信息
            if (dataHntPhb.getReportIdZ() != null) {
                for (ImportList map : importList) {
                    if (map.getReportId() != null && dataHntPhb.getReportIdZ().equals(map.getReportId())) {
                        if (map.getGradeId() != null) {
                            bgxxInfo.setBatch(map.getGradeId());
                        }
                        if (map.getRecordCertificate() != null) {
                            bgxxInfo.setCertificateNo(map.getRecordCertificate());
                        }
                    }
                }
            }

            //默认excel的用量为生产用量
            if (dataObject.getKzfyl() != null) {
                scrz += dataObject.getKzfyl();
                bgxxInfo.setScyl(dataObject.getKzfyl().toString());
                if (dataObject.getSnyl() != null) {
                    //用量比例 等于 本身 除以水泥用量  保留两位小数
                    double result = dataObject.getKzfyl() / dataObject.getSnyl();
                    result = Math.round(result * 100) / 100.0;
                    bgxxInfo.setScylb(String.valueOf(result));
                }
            }
            //赋值材料名称
            if (dataHntPhb.getSampleIdZ() != null) {
                for (Map<String, Object> map : sampleIDs) {
                    if (map.get("SampleID") != null && dataHntPhb.getSampleIdZ().toString().equals(map.get("SampleID").toString())) {
                        bgxxInfo.setClmc(map.get("SampleName").toString());
                        bgxxInfo.setWlmc(map.get("SampleName").toString());
                    }
                }
            }
            //赋值材料规格
            if (dataHntPhb.getGradeIdZ() != null) {
                for (Map<String, Object> map : gradeIds) {
                    if (map.get("GradeID") != null && dataHntPhb.getGradeIdZ().toString().equals(map.get("GradeID").toString())) {
                        bgxxInfo.setClgg(map.get("GradeName").toString());
                        bgxxInfo.setWlgg(map.get("GradeName").toString());
                    }
                }
            }

            mixProportionReport.setKzf(bgxxInfo);
        }


        //外加剂1
        if (dataHntPhb.getReportIdAd() != null && !dataHntPhb.getReportIdAd().isEmpty()) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setXhbgbh(dataHntPhb.getReportIdAd());
            bgxxInfo.setCj(dataHntPhb.getHeadStreamAd());
            //默认协会的用量 为打印用量
            bgxxInfo.setDyyl(dataHntPhb.getFiAd());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioAd());


            //赋值备案证等信息
            if (dataHntPhb.getReportIdAd() != null) {
                for (ImportList map : importList) {
                    if (map.getReportId() != null && dataHntPhb.getReportIdAd().equals(map.getReportId())) {
                        if (map.getGradeId() != null) {
                            bgxxInfo.setBatch(map.getGradeId());
                        }
                        if (map.getRecordCertificate() != null) {
                            bgxxInfo.setCertificateNo(map.getRecordCertificate());
                        }
                    }
                }
            }

            if (StringUtils.isNotBlank(dataHntPhb.getFiAd())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiAd());

                //外加剂掺量：外加剂/（水泥+矿粉+掺和料）生产用料
                double sum = 0d;
                if (dataObject.getKzfyl() != null) {
                    sum += dataObject.getKzfyl();
                }
                if (dataObject.getSnyl() != null) {
                    sum += dataObject.getSnyl();
                }
                dycl = Double.parseDouble(dataHntPhb.getFiAd()) / sum;

            }

            //默认excel的用量为生产用量
            if (dataObject.getWjj1yl() != null) {
                scrz += dataObject.getWjj1yl();

                bgxxInfo.setScyl(dataObject.getWjj1yl().toString());
                if (dataObject.getSnyl() != null) {
                    //用量比例 等于 本身 除以水泥用量  保留两位小数
                    double result = dataObject.getWjj1yl() / dataObject.getSnyl();
                    result = Math.round(result * 100) / 100.0;
                    bgxxInfo.setScylb(String.valueOf(result));
                }

                double sum = 0d;
                if (dataObject.getKzfyl() != null) {
                    sum += dataObject.getKzfyl();
                }
                if (dataObject.getSnyl() != null) {
                    sum += dataObject.getSnyl();
                }
                dycl = dataObject.getWjj1yl() / sum;
            }
            //赋值材料名称
            if (dataHntPhb.getSampleIdAd() != null) {
                for (Map<String, Object> map : sampleIDs) {
                    if (map.get("SampleID") != null && dataHntPhb.getSampleIdAd().toString().equals(map.get("SampleID").toString())) {
                        bgxxInfo.setClmc(map.get("SampleName").toString());
                        bgxxInfo.setWlmc(map.get("SampleName").toString());
                    }
                }
            }
            //赋值材料规格
            if (dataHntPhb.getGradeIdAd() != null) {
                for (Map<String, Object> map : gradeIds) {
                    if (map.get("GradeID") != null && dataHntPhb.getGradeIdAd().toString().equals(map.get("GradeID").toString())) {
                        bgxxInfo.setClgg(map.get("GradeName").toString());
                        bgxxInfo.setWlgg(map.get("GradeName").toString());
                    }
                }
            }

            mixProportionReport.setWjj1(bgxxInfo);
        }


        //外加剂2
        if (dataHntPhb.getReportIdAd2() != null && !dataHntPhb.getReportIdAd2().isEmpty()) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setXhbgbh(dataHntPhb.getReportIdAd2());
            bgxxInfo.setCj(dataHntPhb.getHeadStreamAd2());
            //默认协会的用量 为打印用量
            bgxxInfo.setDyyl(dataHntPhb.getFiAd2());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioAd2());

            if (StringUtils.isNotBlank(dataHntPhb.getFiAd2())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiAd2());
            }


            //赋值备案证等信息
            if (dataHntPhb.getReportIdAd2() != null) {
                for (ImportList map : importList) {
                    if (map.getReportId() != null && dataHntPhb.getReportIdAd2().equals(map.getReportId())) {
                        if (map.getGradeId() != null) {
                            bgxxInfo.setBatch(map.getGradeId());
                        }
                        if (map.getRecordCertificate() != null) {
                            bgxxInfo.setCertificateNo(map.getRecordCertificate());
                        }
                    }
                }
            }

            //默认excel的用量为生产用量
            if (dataObject.getWjj2yl() != null) {
                scrz += dataObject.getWjj2yl();
                bgxxInfo.setScyl(dataObject.getWjj2yl().toString());
                if (dataObject.getSnyl() != null) {
                    //用量比例 等于 本身 除以水泥用量  保留两位小数
                    double result = dataObject.getWjj2yl() / dataObject.getSnyl();
                    result = Math.round(result * 100) / 100.0;
                    bgxxInfo.setScylb(String.valueOf(result));
                }
            }
            //赋值材料名称
            if (dataHntPhb.getSampleIdAd2() != null) {
                for (Map<String, Object> map : sampleIDs) {
                    if (map.get("SampleID") != null && dataHntPhb.getSampleIdAd2().toString().equals(map.get("SampleID").toString())) {
                        bgxxInfo.setClmc(map.get("SampleName").toString());
                        bgxxInfo.setWlmc(map.get("SampleName").toString());
                    }
                }
            }
            //赋值材料规格
            if (dataHntPhb.getGradeIdAd2() != null) {
                for (Map<String, Object> map : gradeIds) {
                    if (map.get("GradeID") != null && dataHntPhb.getGradeIdAd2().toString().equals(map.get("GradeID").toString())) {
                        bgxxInfo.setClgg(map.get("GradeName").toString());
                        bgxxInfo.setWlgg(map.get("GradeName").toString());
                    }
                }
            }

            mixProportionReport.setWjj2(bgxxInfo);
        }


        //粗骨料
        if (dataHntPhb.getReportIdG() != null && !dataHntPhb.getReportIdG().isEmpty()) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setXhbgbh(dataHntPhb.getReportIdG());
            bgxxInfo.setCj(dataHntPhb.getHeadStreamG());
            //默认协会的用量 为打印用量
            bgxxInfo.setDyyl(dataHntPhb.getFiG());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioG());

            if (StringUtils.isNotBlank(dataHntPhb.getFiG())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiG());
            }

            //赋值备案证等信息
            if (dataHntPhb.getReportIdG() != null) {
                for (ImportList map : importList) {
                    if (map.getReportId() != null && dataHntPhb.getReportIdG().equals(map.getReportId())) {
                        if (map.getGradeId() != null) {
                            bgxxInfo.setBatch(map.getGradeId());
                        }
                        if (map.getRecordCertificate() != null) {
                            bgxxInfo.setCertificateNo(map.getRecordCertificate());
                        }
                    }
                }
            }

            //默认excel的用量为生产用量
            if (dataObject.getCglyl() != null) {
                scrz += dataObject.getCglyl();
                bgxxInfo.setScyl(dataObject.getCglyl().toString());
                if (dataObject.getSnyl() != null) {
                    //用量比例 等于 本身 除以水泥用量  保留两位小数
                    double result = dataObject.getCglyl() / dataObject.getSnyl();
                    result = Math.round(result * 100) / 100.0;
                    bgxxInfo.setScylb(String.valueOf(result));
                }
            }
            //赋值材料名称
            if (dataHntPhb.getSampleIdG() != null) {
                for (Map<String, Object> map : sampleIDs) {
                    if (map.get("SampleID") != null && dataHntPhb.getSampleIdG().toString().equals(map.get("SampleID").toString())) {
                        bgxxInfo.setClmc(map.get("SampleName").toString());
                        bgxxInfo.setWlmc(map.get("SampleName").toString());
                    }
                }
            }
            //赋值材料规格
            if (dataHntPhb.getSpecIdG() != null) {
                for (Map<String, Object> map : specIds) {
                    if (map.get("SpecID") != null && dataHntPhb.getSpecIdG().toString().equals(map.get("SpecID").toString())) {
                        bgxxInfo.setClgg(map.get("SpecName").toString());
                        bgxxInfo.setWlgg(map.get("SpecName").toString());
                    }
                }
            }

            mixProportionReport.setCgl(bgxxInfo);
        }


        //细骨料
        if (dataHntPhb.getReportIdS() != null && !dataHntPhb.getReportIdS().isEmpty()) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setXhbgbh(dataHntPhb.getReportIdS());
            bgxxInfo.setCj(dataHntPhb.getHeadStreamS());
            //默认协会的用量 为打印用量
            bgxxInfo.setDyyl(dataHntPhb.getFiS());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioS());

            if (StringUtils.isNotBlank(dataHntPhb.getFiS())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiS());

                //砂率： 细骨料用量/(细骨料生产用量+粗骨料生产用量)*100
                double sum = 0d;
                if (dataObject.getXglyl() != null) {
                    sum += dataObject.getXglyl();
                }
                if (dataObject.getCglyl() != null) {
                    sum += dataObject.getCglyl();
                }
                dysl = Double.parseDouble(dataHntPhb.getFiS()) / sum * 100;
            }

            //赋值备案证等信息
            if (dataHntPhb.getReportIdS() != null) {
                for (ImportList map : importList) {
                    if (map.getReportId() != null && dataHntPhb.getReportIdS().equals(map.getReportId())) {
                        if (map.getGradeId() != null) {
                            bgxxInfo.setBatch(map.getGradeId());
                        }
                        if (map.getRecordCertificate() != null) {
                            bgxxInfo.setCertificateNo(map.getRecordCertificate());
                        }
                    }
                }
            }

            //默认excel的用量为生产用量
            if (dataObject.getXglyl() != null) {
                scrz += dataObject.getXglyl();
                bgxxInfo.setScyl(dataObject.getXglyl().toString());
                if (dataObject.getSnyl() != null) {
                    //用量比例 等于 本身 除以水泥用量  保留两位小数
                    double result = dataObject.getXglyl() / dataObject.getSnyl();
                    result = Math.round(result * 100) / 100.0;
                    bgxxInfo.setScylb(String.valueOf(result));
                }

                double sum = 0d;
                if (dataObject.getXglyl() != null) {
                    sum += dataObject.getXglyl();
                }
                if (dataObject.getCglyl() != null) {
                    sum += dataObject.getCglyl();
                }
                scsl = dataObject.getXglyl() / sum * 100;
            }
            //赋值材料名称
            if (dataHntPhb.getSampleIdS() != null) {
                for (Map<String, Object> map : sampleIDs) {
                    if (map.get("SampleID") != null && dataHntPhb.getSampleIdS().toString().equals(map.get("SampleID").toString())) {
                        bgxxInfo.setClmc(map.get("SampleName").toString());
                        bgxxInfo.setWlmc(map.get("SampleName").toString());
                    }
                }
            }
            //赋值材料规格
            if (dataHntPhb.getSpecIdS() != null) {
                for (Map<String, Object> map : specIds) {
                    if (map.get("SpecID") != null && dataHntPhb.getSpecIdS().toString().equals(map.get("SpecID").toString())) {
                        bgxxInfo.setClgg(map.get("SpecName").toString());
                        bgxxInfo.setWlgg(map.get("SpecName").toString());
                    }
                }
            }

            mixProportionReport.setXgl(bgxxInfo);
        }

        JSONObject jsonObject = JsonUtils.beanToObject(mixProportionReport);
        mix.setProportionMaterial(jsonObject);

        if (dyrz != null) {
            dyrz = Math.round(dyrz * 100) / 100.0;
            mix.setPrintRz(dyrz.toString());
        }
        if (scrz != null) {
            scrz = Math.round(scrz * 100) / 100.0;
            mix.setProductionRz(scrz.toString());
        }

        if (dysjb != null) {
            dysjb = Math.round(dysjb * 100) / 100.0;
            mix.setPrintSjb(dysjb.toString());
        }
        if (scsjb != null) {
            scsjb = Math.round(scsjb * 100) / 100.0;
            mix.setProductionSjb(scsjb.toString());
        }

        if (dysl != null) {
            dysl = Math.round(dysl * 100) / 100.0;
            mix.setPrintSl(dysl.toString());
        }
        if (scsl != null) {
            scsl = Math.round(scsl * 100) / 100.0;
            mix.setProductionSl(scsl.toString());
        }

        if (dycl != null) {
            dycl = Math.round(dycl * 100) / 100.0;
            mix.setPrintCl(dycl.toString());
        }
        if (sccl != null) {
            sccl = Math.round(sccl * 100) / 100.0;
            mix.setProductionCl(sccl.toString());
        }


        //新增品控配合比
        mixProportionMapper.insertSelective(mix);
    }

    //赋值品控配合比对象
    private void setUpdateMixProportion(MixProportion mixProportion, DataHntPhb dataHntPhb, ExcelProportionDataObject dataObject) {

        List<MixProportion> list = mixProportionMapper.getList(new MixProportion().setProportionPhb(dataHntPhb.getMpno()));

        if (list.size() == 0) {
            return;
        }
        MixProportion mix = list.get(0);

        //定死默认创建人为 id 配置文件 的
        mix.setUpdater(createrId == null ? null : Long.parseLong(createrId)).setUpdateTime(new Date()).setCreater(createrId == null ? null : Long.parseLong(createrId))
                .setCreateTime(new Date())
                .setIsDel(0);
        mix.setProportionPhb(dataHntPhb.getMpno());
        mix.setProportionSjyj(dataHntPhb.getMpdesignJudgeBy());
        mix.setProportionQddj(dataHntPhb.getMpdesignStrength());
        mix.setProportionKzqd(dataHntPhb.getMpbreakingStrength());
        mix.setProportionKsdj(dataHntPhb.getMpwaterProofing());
        mix.setProportionQllz("");//强氯离子

        if (dataHntPhb.getMpdesignSlump() != null && !dataHntPhb.getMpdesignSlump().isEmpty()) {
            String[] split = dataHntPhb.getMpdesignSlump().split("±");
            if (split != null) {
                MixProportionTld tld = new MixProportionTld();
                if (split[0] != null) {
                    tld.setQz(split[0]);
                }
                if (split[1] != null) {
                    tld.setHz(split[1]);
                }
                JSONObject jsonObject = JsonUtils.beanToObject(tld);
                mix.setProportionTld(jsonObject);
            }
        }

        mix.setPrintSjb(dataHntPhb.getFiWaterCementRatio());
        mix.setProportionRemarks(dataHntPhb.getMpdesignRemark());


        MixProportionReport mixProportionReport = new MixProportionReport();

        //查询原材料名称 规格 信息
        List<String> sampleIdList = new ArrayList<>();
        if (dataHntPhb.getSampleIdC() != null) {
            sampleIdList.add(dataHntPhb.getSampleIdC().toString());
        }
        if (dataHntPhb.getSampleIdF() != null) {
            sampleIdList.add(dataHntPhb.getSampleIdF().toString());
        }
        if (dataHntPhb.getSampleIdZ() != null) {
            sampleIdList.add(dataHntPhb.getSampleIdZ().toString());
        }
        if (dataHntPhb.getSampleIdS() != null) {
            sampleIdList.add(dataHntPhb.getSampleIdS().toString());
        }
        if (dataHntPhb.getSampleIdG() != null) {
            sampleIdList.add(dataHntPhb.getSampleIdG().toString());
        }
        if (dataHntPhb.getSampleIdAd() != null) {
            sampleIdList.add(dataHntPhb.getSampleIdAd().toString());
        }
        if (dataHntPhb.getSampleIdAd2() != null) {
            sampleIdList.add(dataHntPhb.getSampleIdAd2().toString());
        }

        //材料名称
        List<Map<String, Object>> sampleIDs = new ArrayList<>();
        if (sampleIdList.size() != 0) {
            sampleIDs = m_uploadLaboratoryMapper.findItemSampleBySampleID(sampleIdList);
        }


        List<String> gradeIdList = new ArrayList<>();
        if (dataHntPhb.getGradeIdC() != null) {
            gradeIdList.add(dataHntPhb.getGradeIdC().toString());
        }
        if (dataHntPhb.getGradeIdF() != null) {
            gradeIdList.add(dataHntPhb.getGradeIdF().toString());
        }
        if (dataHntPhb.getGradeIdS() != null) {
            gradeIdList.add(dataHntPhb.getGradeIdS().toString());
        }
        if (dataHntPhb.getGradeIdZ() != null) {
            gradeIdList.add(dataHntPhb.getGradeIdZ().toString());
        }
        if (dataHntPhb.getGradeIdG() != null) {
            gradeIdList.add(dataHntPhb.getGradeIdG().toString());
        }
        if (dataHntPhb.getGradeIdAd() != null) {
            gradeIdList.add(dataHntPhb.getGradeIdAd().toString());
        }
        if (dataHntPhb.getGradeIdAd2() != null) {
            gradeIdList.add(dataHntPhb.getGradeIdAd2().toString());
        }
        List<Map<String, Object>> gradeIds = new ArrayList<>();

        if (gradeIdList.size() != 0) {
            gradeIds = m_uploadLaboratoryMapper.findItemGradeByGradeId(gradeIdList);
        }


        List<String> specIdList = new ArrayList<>();
        if (dataHntPhb.getSpecIdC() != null) {
            specIdList.add(dataHntPhb.getSpecIdC().toString());
        }
        if (dataHntPhb.getSpecIdF() != null) {
            specIdList.add(dataHntPhb.getSpecIdF().toString());
        }
        if (dataHntPhb.getSpecIdZ() != null) {
            specIdList.add(dataHntPhb.getSpecIdZ().toString());
        }
        if (dataHntPhb.getSpecIdG() != null) {
            specIdList.add(dataHntPhb.getSpecIdG().toString());
        }
        if (dataHntPhb.getSpecIdS() != null) {
            specIdList.add(dataHntPhb.getSpecIdS().toString());
        }
        if (dataHntPhb.getSpecIdAd() != null) {
            specIdList.add(dataHntPhb.getSpecIdAd().toString());
        }
        if (dataHntPhb.getSpecIdAd2() != null) {
            specIdList.add(dataHntPhb.getSpecIdAd2().toString());
        }
        List<Map<String, Object>> specIds = new ArrayList<>();

        if (specIdList.size() != 0) {
            specIds = m_uploadLaboratoryMapper.findItemSpecBySpecId(specIdList);
        }

        List<String> reports = new ArrayList<>();
        //报告编号
        if (StringUtils.isNotBlank(dataHntPhb.getReportIdC())) {
            reports.add(dataHntPhb.getReportIdC());
        }
        if (StringUtils.isNotBlank(dataHntPhb.getReportIdF())) {
            reports.add(dataHntPhb.getReportIdF());
        }
        if (StringUtils.isNotBlank(dataHntPhb.getReportIdZ())) {
            reports.add(dataHntPhb.getReportIdZ());
        }
        if (StringUtils.isNotBlank(dataHntPhb.getReportIdS())) {
            reports.add(dataHntPhb.getReportIdS());
        }
        if (StringUtils.isNotBlank(dataHntPhb.getReportIdG())) {
            reports.add(dataHntPhb.getReportIdG());
        }
        if (StringUtils.isNotBlank(dataHntPhb.getReportIdAd())) {
            reports.add(dataHntPhb.getReportIdAd());
        }
        if (StringUtils.isNotBlank(dataHntPhb.getReportIdAd2())) {
            reports.add(dataHntPhb.getReportIdAd2());
        }

        List<ImportList> importList = new ArrayList<>();
        if (reports.size() != 0) {
            importList = importListMapper.findImportListByReportId(reports);
        }


        //容重
        Double scrz = 0d;
        Double dyrz = 0d;

        //水胶比
        Double scsjb = 0d;
        Double dysjb = 0d;

        //砂率
        Double scsl = 0d;
        Double dysl = 0d;

        //外加剂掺量
        Double sccl = 0d;
        Double dycl = 0d;


        //水泥
        if (dataHntPhb.getReportIdC() != null && !dataHntPhb.getReportIdC().isEmpty()) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setXhbgbh(dataHntPhb.getReportIdC());
            bgxxInfo.setCj(dataHntPhb.getHeadStreamC());
            //默认协会的用量 为打印用量
            bgxxInfo.setDyyl(dataHntPhb.getFiC());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioC());

            if (StringUtils.isNotBlank(dataHntPhb.getFiC())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiC());
            }


            //默认excel的用量为生产用量
            if (dataObject.getSnyl() != null) {
                bgxxInfo.setScyl(dataObject.getSnyl().toString());
                bgxxInfo.setScylb("1");

                scrz += dataObject.getSnyl();
            }
            //赋值材料名称
            if (dataHntPhb.getSampleIdC() != null) {
                for (Map<String, Object> map : sampleIDs) {
                    if (map.get("SampleID") != null && dataHntPhb.getSampleIdC().toString().equals(map.get("SampleID").toString())) {
                        bgxxInfo.setClmc(map.get("SampleName").toString());
                        bgxxInfo.setWlmc(map.get("SampleName").toString());
                    }
                }
            }
            //赋值材料规格
            if (dataHntPhb.getGradeIdC() != null) {
                for (Map<String, Object> map : gradeIds) {
                    if (map.get("GradeID") != null && dataHntPhb.getGradeIdC().toString().equals(map.get("GradeID").toString())) {
                        bgxxInfo.setClgg(map.get("GradeName").toString());
                        bgxxInfo.setWlgg(map.get("GradeName").toString());
                    }
                }
            }

            //赋值备案证等信息
            if (dataHntPhb.getReportIdC() != null) {
                for (ImportList map : importList) {
                    if (map.getReportId() != null && dataHntPhb.getReportIdC().equals(map.getReportId())) {
                        if (map.getGradeId() != null) {
                            bgxxInfo.setBatch(map.getGradeId());
                        }
                        if (map.getRecordCertificate() != null) {
                            bgxxInfo.setCertificateNo(map.getRecordCertificate());
                        }
                    }
                }
            }

            mixProportionReport.setSn(bgxxInfo);
        }


        //水
        if (dataHntPhb.getFiW() != null) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setClmc("水");
            bgxxInfo.setWlmc("水");
            bgxxInfo.setClgg("清水");
            bgxxInfo.setWlgg("清水");
            bgxxInfo.setDyyl(dataHntPhb.getFiW());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioW());

            if (StringUtils.isNotBlank(dataHntPhb.getFiW())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiW());

                //水胶比公式：(水 / （水泥+矿粉+粉煤灰）生产用量)*100)/1000
                double sum = 0d;
                if (dataObject.getSnyl() != null) {
                    sum += dataObject.getSnyl();
                }
                if (dataObject.getKzfyl() != null) {
                    sum += dataObject.getKzfyl();
                }
                if (dataObject.getFmhyl() != null) {
                    sum += dataObject.getFmhyl();
                }

                dysjb = (Double.parseDouble(dataHntPhb.getFiW()) / sum * 100) / 1000;
            }

            //默认excel的用量为生产用量
            if (dataObject.getWateryl() != null) {
                scrz += dataObject.getWateryl();
                bgxxInfo.setScyl(dataObject.getWateryl().toString());
                if (dataObject.getSnyl() != null) {
                    //用量比例 等于 本身 除以水泥用量  保留两位小数
                    double result = dataObject.getWateryl() / dataObject.getSnyl();
                    result = Math.round(result * 100) / 100.0;
                    bgxxInfo.setScylb(String.valueOf(result));
                }

                double sum = 0d;
                if (dataObject.getSnyl() != null) {
                    sum += dataObject.getSnyl();
                }
                if (dataObject.getKzfyl() != null) {
                    sum += dataObject.getKzfyl();
                }
                if (dataObject.getFmhyl() != null) {
                    sum += dataObject.getFmhyl();
                }

                scsjb = (dataObject.getWateryl() / sum * 100) / 1000;

            }


            mixProportionReport.setWater(bgxxInfo);
        }

        //粉煤灰
        if (dataHntPhb.getReportIdF() != null && !dataHntPhb.getReportIdF().isEmpty()) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setXhbgbh(dataHntPhb.getReportIdF());
            bgxxInfo.setCj(dataHntPhb.getHeadStreamF());
            //默认协会的用量 为打印用量
            bgxxInfo.setDyyl(dataHntPhb.getFiF());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioF());

            if (StringUtils.isNotBlank(dataHntPhb.getFiF())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiF());
            }


            //赋值备案证等信息
            if (dataHntPhb.getReportIdF() != null) {
                for (ImportList map : importList) {
                    if (map.getReportId() != null && dataHntPhb.getReportIdF().equals(map.getReportId())) {
                        if (map.getGradeId() != null) {
                            bgxxInfo.setBatch(map.getGradeId());
                        }
                        if (map.getRecordCertificate() != null) {
                            bgxxInfo.setCertificateNo(map.getRecordCertificate());
                        }
                    }
                }
            }

            //默认excel的用量为生产用量
            if (dataObject.getFmhyl() != null) {
                scrz += dataObject.getFmhyl();
                bgxxInfo.setScyl(dataObject.getFmhyl().toString());
                if (dataObject.getSnyl() != null) {
                    //用量比例 等于 本身 除以水泥用量  保留两位小数
                    double result = dataObject.getFmhyl() / dataObject.getSnyl();
                    result = Math.round(result * 100) / 100.0;
                    bgxxInfo.setScylb(String.valueOf(result));
                }

            }
            //赋值材料名称
            if (dataHntPhb.getSampleIdF() != null) {
                for (Map<String, Object> map : sampleIDs) {
                    if (map.get("SampleID") != null && dataHntPhb.getSampleIdF().toString().equals(map.get("SampleID").toString())) {
                        bgxxInfo.setClmc(map.get("SampleName").toString());
                        bgxxInfo.setWlmc(map.get("SampleName").toString());
                    }
                }
            }
            //赋值材料规格
            if (dataHntPhb.getGradeIdF() != null) {
                String name = "";
                for (Map<String, Object> map : gradeIds) {
                    if (map.get("GradeID") != null && dataHntPhb.getGradeIdF().toString().toString().equals(map.get("GradeID").toString())) {
                        name = map.get("GradeName").toString();
                    }
                }

                if (dataHntPhb.getSpecIdF() != null) {
                    for (Map<String, Object> map : specIds) {
                        if (map.get("SpecID") != null && dataHntPhb.getSpecIdF().toString().equals(map.get("SpecID").toString())) {
                            name = map.get("SpecName").toString() + name;
                        }
                    }
                }

                bgxxInfo.setClgg(name);
                bgxxInfo.setWlgg(name);
            }

            mixProportionReport.setFmh(bgxxInfo);
        }


        //矿渣粉
        if (dataHntPhb.getReportIdZ() != null && !dataHntPhb.getReportIdZ().isEmpty()) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setXhbgbh(dataHntPhb.getReportIdZ());
            bgxxInfo.setCj(dataHntPhb.getHeadStreamZ());
            //默认协会的用量 为打印用量
            bgxxInfo.setDyyl(dataHntPhb.getFiZ());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioZ());

            if (StringUtils.isNotBlank(dataHntPhb.getFiZ())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiZ());
            }

            //赋值备案证等信息
            if (dataHntPhb.getReportIdZ() != null) {
                for (ImportList map : importList) {
                    if (map.getReportId() != null && dataHntPhb.getReportIdZ().equals(map.getReportId())) {
                        if (map.getGradeId() != null) {
                            bgxxInfo.setBatch(map.getGradeId());
                        }
                        if (map.getRecordCertificate() != null) {
                            bgxxInfo.setCertificateNo(map.getRecordCertificate());
                        }
                    }
                }
            }

            //默认excel的用量为生产用量
            if (dataObject.getKzfyl() != null) {
                scrz += dataObject.getKzfyl();
                bgxxInfo.setScyl(dataObject.getKzfyl().toString());
                if (dataObject.getSnyl() != null) {
                    //用量比例 等于 本身 除以水泥用量  保留两位小数
                    double result = dataObject.getKzfyl() / dataObject.getSnyl();
                    result = Math.round(result * 100) / 100.0;
                    bgxxInfo.setScylb(String.valueOf(result));
                }
            }
            //赋值材料名称
            if (dataHntPhb.getSampleIdZ() != null) {
                for (Map<String, Object> map : sampleIDs) {
                    if (map.get("SampleID") != null && dataHntPhb.getSampleIdZ().toString().equals(map.get("SampleID").toString())) {
                        bgxxInfo.setClmc(map.get("SampleName").toString());
                        bgxxInfo.setWlmc(map.get("SampleName").toString());
                    }
                }
            }
            //赋值材料规格
            if (dataHntPhb.getGradeIdZ() != null) {
                for (Map<String, Object> map : gradeIds) {
                    if (map.get("GradeID") != null && dataHntPhb.getGradeIdZ().toString().equals(map.get("GradeID").toString())) {
                        bgxxInfo.setClgg(map.get("GradeName").toString());
                        bgxxInfo.setWlgg(map.get("GradeName").toString());
                    }
                }
            }

            mixProportionReport.setKzf(bgxxInfo);
        }


        //外加剂1
        if (dataHntPhb.getReportIdAd() != null && !dataHntPhb.getReportIdAd().isEmpty()) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setXhbgbh(dataHntPhb.getReportIdAd());
            bgxxInfo.setCj(dataHntPhb.getHeadStreamAd());
            //默认协会的用量 为打印用量
            bgxxInfo.setDyyl(dataHntPhb.getFiAd());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioAd());


            //赋值备案证等信息
            if (dataHntPhb.getReportIdAd() != null) {
                for (ImportList map : importList) {
                    if (map.getReportId() != null && dataHntPhb.getReportIdAd().equals(map.getReportId())) {
                        if (map.getGradeId() != null) {
                            bgxxInfo.setBatch(map.getGradeId());
                        }
                        if (map.getRecordCertificate() != null) {
                            bgxxInfo.setCertificateNo(map.getRecordCertificate());
                        }
                    }
                }
            }

            if (StringUtils.isNotBlank(dataHntPhb.getFiAd())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiAd());

                //外加剂掺量：外加剂/（水泥+矿粉+掺和料）生产用料
                double sum = 0d;
                if (dataObject.getKzfyl() != null) {
                    sum += dataObject.getKzfyl();
                }
                if (dataObject.getSnyl() != null) {
                    sum += dataObject.getSnyl();
                }
                dycl = Double.parseDouble(dataHntPhb.getFiAd()) / sum;

            }

            //默认excel的用量为生产用量
            if (dataObject.getWjj1yl() != null) {
                scrz += dataObject.getWjj1yl();

                bgxxInfo.setScyl(dataObject.getWjj1yl().toString());
                if (dataObject.getSnyl() != null) {
                    //用量比例 等于 本身 除以水泥用量  保留两位小数
                    double result = dataObject.getWjj1yl() / dataObject.getSnyl();
                    result = Math.round(result * 100) / 100.0;
                    bgxxInfo.setScylb(String.valueOf(result));
                }

                double sum = 0d;
                if (dataObject.getKzfyl() != null) {
                    sum += dataObject.getKzfyl();
                }
                if (dataObject.getSnyl() != null) {
                    sum += dataObject.getSnyl();
                }
                dycl = dataObject.getWjj1yl() / sum;
            }
            //赋值材料名称
            if (dataHntPhb.getSampleIdAd() != null) {
                for (Map<String, Object> map : sampleIDs) {
                    if (map.get("SampleID") != null && dataHntPhb.getSampleIdAd().toString().equals(map.get("SampleID").toString())) {
                        bgxxInfo.setClmc(map.get("SampleName").toString());
                        bgxxInfo.setWlmc(map.get("SampleName").toString());
                    }
                }
            }
            //赋值材料规格
            if (dataHntPhb.getGradeIdAd() != null) {
                for (Map<String, Object> map : gradeIds) {
                    if (map.get("GradeID") != null && dataHntPhb.getGradeIdAd().toString().equals(map.get("GradeID").toString())) {
                        bgxxInfo.setClgg(map.get("GradeName").toString());
                        bgxxInfo.setWlgg(map.get("GradeName").toString());
                    }
                }
            }

            mixProportionReport.setWjj1(bgxxInfo);
        }


        //外加剂2
        if (dataHntPhb.getReportIdAd2() != null && !dataHntPhb.getReportIdAd2().isEmpty()) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setXhbgbh(dataHntPhb.getReportIdAd2());
            bgxxInfo.setCj(dataHntPhb.getHeadStreamAd2());
            //默认协会的用量 为打印用量
            bgxxInfo.setDyyl(dataHntPhb.getFiAd2());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioAd2());

            if (StringUtils.isNotBlank(dataHntPhb.getFiAd2())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiAd2());
            }


            //赋值备案证等信息
            if (dataHntPhb.getReportIdAd2() != null) {
                for (ImportList map : importList) {
                    if (map.getReportId() != null && dataHntPhb.getReportIdAd2().equals(map.getReportId())) {
                        if (map.getGradeId() != null) {
                            bgxxInfo.setBatch(map.getGradeId());
                        }
                        if (map.getRecordCertificate() != null) {
                            bgxxInfo.setCertificateNo(map.getRecordCertificate());
                        }
                    }
                }
            }

            //默认excel的用量为生产用量
            if (dataObject.getWjj2yl() != null) {
                scrz += dataObject.getWjj2yl();
                bgxxInfo.setScyl(dataObject.getWjj2yl().toString());
                if (dataObject.getSnyl() != null) {
                    //用量比例 等于 本身 除以水泥用量  保留两位小数
                    double result = dataObject.getWjj2yl() / dataObject.getSnyl();
                    result = Math.round(result * 100) / 100.0;
                    bgxxInfo.setScylb(String.valueOf(result));
                }
            }
            //赋值材料名称
            if (dataHntPhb.getSampleIdAd2() != null) {
                for (Map<String, Object> map : sampleIDs) {
                    if (map.get("SampleID") != null && dataHntPhb.getSampleIdAd2().toString().equals(map.get("SampleID").toString())) {
                        bgxxInfo.setClmc(map.get("SampleName").toString());
                        bgxxInfo.setWlmc(map.get("SampleName").toString());
                    }
                }
            }
            //赋值材料规格
            if (dataHntPhb.getGradeIdAd2() != null) {
                for (Map<String, Object> map : gradeIds) {
                    if (map.get("GradeID") != null && dataHntPhb.getGradeIdAd2().toString().equals(map.get("GradeID").toString())) {
                        bgxxInfo.setClgg(map.get("GradeName").toString());
                        bgxxInfo.setWlgg(map.get("GradeName").toString());
                    }
                }
            }

            mixProportionReport.setWjj2(bgxxInfo);
        }


        //粗骨料
        if (dataHntPhb.getReportIdG() != null && !dataHntPhb.getReportIdG().isEmpty()) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setXhbgbh(dataHntPhb.getReportIdG());
            bgxxInfo.setCj(dataHntPhb.getHeadStreamG());
            //默认协会的用量 为打印用量
            bgxxInfo.setDyyl(dataHntPhb.getFiG());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioG());

            if (StringUtils.isNotBlank(dataHntPhb.getFiG())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiG());
            }

            //赋值备案证等信息
            if (dataHntPhb.getReportIdG() != null) {
                for (ImportList map : importList) {
                    if (map.getReportId() != null && dataHntPhb.getReportIdG().equals(map.getReportId())) {
                        if (map.getGradeId() != null) {
                            bgxxInfo.setBatch(map.getGradeId());
                        }
                        if (map.getRecordCertificate() != null) {
                            bgxxInfo.setCertificateNo(map.getRecordCertificate());
                        }
                    }
                }
            }

            //默认excel的用量为生产用量
            if (dataObject.getCglyl() != null) {
                scrz += dataObject.getCglyl();
                bgxxInfo.setScyl(dataObject.getCglyl().toString());
                if (dataObject.getSnyl() != null) {
                    //用量比例 等于 本身 除以水泥用量  保留两位小数
                    double result = dataObject.getCglyl() / dataObject.getSnyl();
                    result = Math.round(result * 100) / 100.0;
                    bgxxInfo.setScylb(String.valueOf(result));
                }
            }
            //赋值材料名称
            if (dataHntPhb.getSampleIdG() != null) {
                for (Map<String, Object> map : sampleIDs) {
                    if (map.get("SampleID") != null && dataHntPhb.getSampleIdG().toString().equals(map.get("SampleID").toString())) {
                        bgxxInfo.setClmc(map.get("SampleName").toString());
                        bgxxInfo.setWlmc(map.get("SampleName").toString());
                    }
                }
            }
            //赋值材料规格
            if (dataHntPhb.getSpecIdG() != null) {
                for (Map<String, Object> map : specIds) {
                    if (map.get("SpecID") != null && dataHntPhb.getSpecIdG().toString().equals(map.get("SpecID").toString())) {
                        bgxxInfo.setClgg(map.get("SpecName").toString());
                        bgxxInfo.setWlgg(map.get("SpecName").toString());
                    }
                }
            }

            mixProportionReport.setCgl(bgxxInfo);
        }


        //细骨料
        if (dataHntPhb.getReportIdS() != null && !dataHntPhb.getReportIdS().isEmpty()) {
            MixProportionReport.BgxxInfo bgxxInfo = new MixProportionReport.BgxxInfo();
            bgxxInfo.setXhbgbh(dataHntPhb.getReportIdS());
            bgxxInfo.setCj(dataHntPhb.getHeadStreamS());
            //默认协会的用量 为打印用量
            bgxxInfo.setDyyl(dataHntPhb.getFiS());
            bgxxInfo.setDyylb(dataHntPhb.getFiRatioS());

            if (StringUtils.isNotBlank(dataHntPhb.getFiS())) {
                dyrz += Double.parseDouble(dataHntPhb.getFiS());

                //砂率： 细骨料用量/(细骨料生产用量+粗骨料生产用量)*100
                double sum = 0d;
                if (dataObject.getXglyl() != null) {
                    sum += dataObject.getXglyl();
                }
                if (dataObject.getCglyl() != null) {
                    sum += dataObject.getCglyl();
                }
                dysl = Double.parseDouble(dataHntPhb.getFiS()) / sum * 100;
            }

            //赋值备案证等信息
            if (dataHntPhb.getReportIdS() != null) {
                for (ImportList map : importList) {
                    if (map.getReportId() != null && dataHntPhb.getReportIdS().equals(map.getReportId())) {
                        if (map.getGradeId() != null) {
                            bgxxInfo.setBatch(map.getGradeId());
                        }
                        if (map.getRecordCertificate() != null) {
                            bgxxInfo.setCertificateNo(map.getRecordCertificate());
                        }
                    }
                }
            }

            //默认excel的用量为生产用量
            if (dataObject.getXglyl() != null) {
                scrz += dataObject.getXglyl();
                bgxxInfo.setScyl(dataObject.getXglyl().toString());
                if (dataObject.getSnyl() != null) {
                    //用量比例 等于 本身 除以水泥用量  保留两位小数
                    double result = dataObject.getXglyl() / dataObject.getSnyl();
                    result = Math.round(result * 100) / 100.0;
                    bgxxInfo.setScylb(String.valueOf(result));
                }

                double sum = 0d;
                if (dataObject.getXglyl() != null) {
                    sum += dataObject.getXglyl();
                }
                if (dataObject.getCglyl() != null) {
                    sum += dataObject.getCglyl();
                }
                scsl = dataObject.getXglyl() / sum * 100;
            }
            //赋值材料名称
            if (dataHntPhb.getSampleIdS() != null) {
                for (Map<String, Object> map : sampleIDs) {
                    if (map.get("SampleID") != null && dataHntPhb.getSampleIdS().toString().equals(map.get("SampleID").toString())) {
                        bgxxInfo.setClmc(map.get("SampleName").toString());
                        bgxxInfo.setWlmc(map.get("SampleName").toString());
                    }
                }
            }
            //赋值材料规格
            if (dataHntPhb.getSpecIdS() != null) {
                for (Map<String, Object> map : specIds) {
                    if (map.get("SpecID") != null && dataHntPhb.getSpecIdS().toString().equals(map.get("SpecID").toString())) {
                        bgxxInfo.setClgg(map.get("SpecName").toString());
                        bgxxInfo.setWlgg(map.get("SpecName").toString());
                    }
                }
            }

            mixProportionReport.setXgl(bgxxInfo);
        }

        JSONObject jsonObject = JsonUtils.beanToObject(mixProportionReport);
        mix.setProportionMaterial(jsonObject);

        if (dyrz != null) {
            dyrz = Math.round(dyrz * 100) / 100.0;
            mix.setPrintRz(dyrz.toString());
        }
        if (scrz != null) {
            scrz = Math.round(scrz * 100) / 100.0;
            mix.setProductionRz(scrz.toString());
        }

        if (dysjb != null) {
            dysjb = Math.round(dysjb * 100) / 100.0;
            mix.setPrintSjb(dysjb.toString());
        }
        if (scsjb != null) {
            scsjb = Math.round(scsjb * 100) / 100.0;
            mix.setProductionSjb(scsjb.toString());
        }

        if (dysl != null) {
            dysl = Math.round(dysl * 100) / 100.0;
            mix.setPrintSl(dysl.toString());
        }
        if (scsl != null) {
            scsl = Math.round(scsl * 100) / 100.0;
            mix.setProductionSl(scsl.toString());
        }

        if (dycl != null) {
            dycl = Math.round(dycl * 100) / 100.0;
            mix.setPrintCl(dycl.toString());
        }
        if (sccl != null) {
            sccl = Math.round(sccl * 100) / 100.0;
            mix.setProductionCl(sccl.toString());
        }

        //修改品控配合比
        mixProportionMapper.updateByPrimaryKeySelective(mix);
    }


    public void uploadAssociation(MixProportion entity) {
        log.info("同步新增配合比开始，配合比编号：【{}】", entity.getProportionPhb());

        //查询所有类型批检配置
        List<ExperimentGenConfig> experimentGenConfigList = experimentGenConfigMapper.getList(new ExperimentGenConfig().setCheckType(CheckEnum.BATCH.getCode()));

        //协会配合比对象
        DataHntPhb dataHntPhb = new DataHntPhb();
        dataHntPhb.setMpno(entity.getProportionPhb());//配合比编号
        dataHntPhb.setMpdesignStrength(entity.getProportionQddj());//强度等级

        if (entity.getProportionTld() != null) {
            MixProportionTld tld = entity.getProportionTld().toJavaObject(MixProportionTld.class);
            if (tld.getQz() != null && !tld.getQz().isEmpty() && tld.getHz() != null && !tld.getHz().isEmpty()) {
                dataHntPhb.setMpdesignSlump(tld.getQz() + "±" + tld.getHz());//设计塌落度
            }

        }

        if (StringUtils.isNotBlank(entity.getProportionKzqd())) {
            dataHntPhb.setMpbreakingStrength(entity.getProportionKzqd());//抗折强度
        } else {
            dataHntPhb.setMpbreakingStrength("---");//抗折强度
        }


        List<String> newList = Arrays.asList("P6", "P8", "P10", "P12");

        //配合比不包含抗渗等级的 为true
        boolean found = true;
        for (String s : newList) {
            if (entity.getProportionPhb().contains(s)) {
                found = false;
                break;
            }
        }

        //是向下兼容 就需要把默认的不包含P 的编号 的抗渗等级置空
        if (entity.getBackwardCompatible() != null && 1 == entity.getBackwardCompatible() && found) {
            dataHntPhb.setMpwaterProofing("---");//抗渗等级
        } else {
            if (StringUtils.isNotBlank(entity.getProportionKsdj())) {
                dataHntPhb.setMpwaterProofing(entity.getProportionKsdj());//抗渗等级
            } else {
                dataHntPhb.setMpwaterProofing("---");//抗渗等级
            }

        }

        dataHntPhb.setMpdesignJudgeBy(entity.getProportionSjyj());//设计依据
        dataHntPhb.setMpdesignRemark(entity.getProportionRemarks());//备注
        dataHntPhb.setIsChecked((long) 1);//默认为1

        //水灰比
        if (StringUtils.isNotBlank(entity.getProductionSjb())) {
            dataHntPhb.setFiWaterCementRatio(entity.getProductionSjb());
        }

        if (entity.getCreater() != null) {
            User user = userMapper.selectByPrimaryKey(entity.getCreater());
            if (user != null) {
                dataHntPhb.setTrialMan(user.getSocietyUserName());
            }
        }

        String uploadFlag = UploadFlagUtils.CtoGB_Num("0000000000", "z", new Date(), null);
        dataHntPhb.setUploadFlag(uploadFlag);


        //原材料报告信息 json 转对象
        MixProportionReport mixProportionReport = entity.getProportionMaterial().toJavaObject(MixProportionReport.class);
        if (mixProportionReport != null) {
            MixProportionReport.BgxxInfo sn = mixProportionReport.getSn();
            MixProportionReport.BgxxInfo water = mixProportionReport.getWater();
            MixProportionReport.BgxxInfo fmh = mixProportionReport.getFmh();
            MixProportionReport.BgxxInfo kzf = mixProportionReport.getKzf();
            MixProportionReport.BgxxInfo cgl = mixProportionReport.getCgl();
            MixProportionReport.BgxxInfo xgl = mixProportionReport.getXgl();
            MixProportionReport.BgxxInfo wjj1 = mixProportionReport.getWjj1();
            MixProportionReport.BgxxInfo wjj2 = mixProportionReport.getWjj2();

            //打印用量传值到 协会
            dataHntPhb.setFiC(NullUtils.ifNull(sn.getDyyl()));//水泥用量
            dataHntPhb.setFiF(NullUtils.ifNull(fmh.getDyyl()));//粉煤灰用量
            dataHntPhb.setFiZ(NullUtils.ifNull(kzf.getDyyl()));//矿渣粉用量
            dataHntPhb.setFiW(NullUtils.ifNull(water.getDyyl()));//水用量
            dataHntPhb.setFiS(NullUtils.ifNull(xgl.getDyyl()));//细骨料用量
            dataHntPhb.setFiG(NullUtils.ifNull(cgl.getDyyl()));//粗骨料用量
            dataHntPhb.setFiAd(NullUtils.ifNull(wjj1.getDyyl()));//外加剂1用量
            dataHntPhb.setFiAd2(NullUtils.ifNull(wjj2.getDyyl()));//外加剂2用量
            dataHntPhb.setFiRatioC(NullUtils.ifNull(sn.getDyylb()));//水泥用量比例
            dataHntPhb.setFiRatioF(NullUtils.ifNull(fmh.getDyylb()));//粉煤灰用量比例
            dataHntPhb.setFiRatioZ(NullUtils.ifNull(kzf.getDyylb()));//矿渣粉用量比例
            dataHntPhb.setFiRatioW(NullUtils.ifNull(water.getDyylb()));//水用量比例
            dataHntPhb.setFiRatioS(NullUtils.ifNull(xgl.getDyylb()));//细骨料用量比例
            dataHntPhb.setFiRatioG(NullUtils.ifNull(cgl.getDyylb()));//粗骨料用量比例
            dataHntPhb.setFiRatioAd(NullUtils.ifNull(wjj1.getDyylb()));//外加剂1用量比例
            dataHntPhb.setFiRatioAd2(NullUtils.ifNull(wjj2.getDyylb()));//外加剂2用量比例

            //报告编号
            dataHntPhb.setReportIdC(sn.getXhbgbh());
            dataHntPhb.setReportIdF(fmh.getXhbgbh());
            dataHntPhb.setReportIdZ(kzf.getXhbgbh());
            dataHntPhb.setReportIdS(xgl.getXhbgbh());
            dataHntPhb.setReportIdG(cgl.getXhbgbh());
            dataHntPhb.setReportIdAd(wjj1.getXhbgbh());
            dataHntPhb.setReportIdAd2(wjj2.getXhbgbh());

            //厂家  根据配置传值
            //1 -- 同一厂家   2 -- 同一供应商

            for (ExperimentGenConfig genConfig : experimentGenConfigList) {
                if (MaterialsEnum.CEMENT.getCode().equals(genConfig.getExperimentType())) {
                    if (genConfig.getQualifiedType() != null) {
                        if ("1".equals(String.valueOf(genConfig.getQualifiedType()))) {
                            dataHntPhb.setHeadStreamC(sn.getCj());
                        } else if ("2".equals(String.valueOf(genConfig.getQualifiedType()))) {
                            dataHntPhb.setHeadStreamC(sn.getGys());
                        }
                    }
                } else if (MaterialsEnum.FLY.getCode().equals(genConfig.getExperimentType())) {
                    if (genConfig.getQualifiedType() != null) {
                        if ("1".equals(String.valueOf(genConfig.getQualifiedType()))) {
                            dataHntPhb.setHeadStreamF(fmh.getCj());
                        } else if ("2".equals(String.valueOf(genConfig.getQualifiedType()))) {
                            dataHntPhb.setHeadStreamF(fmh.getGys());
                        }
                    }
                } else if (MaterialsEnum.SLAG.getCode().equals(genConfig.getExperimentType())) {
                    if (genConfig.getQualifiedType() != null) {
                        if ("1".equals(String.valueOf(genConfig.getQualifiedType()))) {
                            dataHntPhb.setHeadStreamZ(kzf.getCj());
                        } else if ("2".equals(String.valueOf(genConfig.getQualifiedType()))) {
                            dataHntPhb.setHeadStreamZ(kzf.getGys());
                        }
                    }
                } else if (MaterialsEnum.FINE.getCode().equals(genConfig.getExperimentType())) {
                    if (genConfig.getQualifiedType() != null) {
                        if ("1".equals(String.valueOf(genConfig.getQualifiedType()))) {
                            dataHntPhb.setHeadStreamS(xgl.getCj());
                        } else if ("2".equals(String.valueOf(genConfig.getQualifiedType()))) {
                            dataHntPhb.setHeadStreamS(xgl.getGys());
                        }
                    }
                } else if (MaterialsEnum.COARSE.getCode().equals(genConfig.getExperimentType())) {
                    if (genConfig.getQualifiedType() != null) {
                        if ("1".equals(String.valueOf(genConfig.getQualifiedType()))) {
                            dataHntPhb.setHeadStreamG(cgl.getCj());
                        } else if ("2".equals(String.valueOf(genConfig.getQualifiedType()))) {
                            dataHntPhb.setHeadStreamG(cgl.getGys());
                        }
                    }
                } else if (MaterialsEnum.ADMIXTURE.getCode().equals(genConfig.getExperimentType())) {
                    if (genConfig.getQualifiedType() != null) {
                        if ("1".equals(String.valueOf(genConfig.getQualifiedType()))) {
                            dataHntPhb.setHeadStreamAd(wjj1.getCj());
                            dataHntPhb.setHeadStreamAd2(wjj2.getCj());
                        } else if ("2".equals(String.valueOf(genConfig.getQualifiedType()))) {
                            dataHntPhb.setHeadStreamAd(wjj1.getGys());
                            dataHntPhb.setHeadStreamAd2(wjj2.getGys());
                        }
                    }
                }


            }


            //样品 规格 信息
            //水泥
            if (sn.getPktzid() != null && !sn.getPktzid().isEmpty()) {
                List<AssociationStorage> list = associationStorageMapper.getList(new AssociationStorage().setExperimentId(Long.parseLong(sn.getPktzid())));
                if (list != null && list.size() != 0) {
                    AssociationStorage storage = list.get(0);
                    dataHntPhb.setSampleIdC(storage.getSampleId());
                    dataHntPhb.setSpecIdC(storage.getSpecId());
                    dataHntPhb.setGradeIdC(storage.getGradeId());
                }
            }
            //矿渣粉
            if (kzf.getPktzid() != null && !kzf.getPktzid().isEmpty()) {
                List<AssociationStorage> list = associationStorageMapper.getList(new AssociationStorage().setExperimentId(Long.parseLong(kzf.getPktzid())));
                if (list != null && list.size() != 0) {
                    AssociationStorage storage = list.get(0);
                    dataHntPhb.setSampleIdZ(storage.getSampleId());
                    dataHntPhb.setSpecIdZ(storage.getSpecId());
                    dataHntPhb.setGradeIdZ(storage.getGradeId());
                }
            }
            //粉煤灰
            if (fmh.getPktzid() != null && !fmh.getPktzid().isEmpty()) {
                List<AssociationStorage> list = associationStorageMapper.getList(new AssociationStorage().setExperimentId(Long.parseLong(fmh.getPktzid())));
                if (list != null && list.size() != 0) {
                    AssociationStorage storage = list.get(0);
                    dataHntPhb.setSampleIdF(storage.getSampleId());
                    dataHntPhb.setSpecIdF(storage.getSpecId());
                    dataHntPhb.setGradeIdF(storage.getGradeId());
                }
            }
            //细骨料
            if (xgl.getPktzid() != null && !xgl.getPktzid().isEmpty()) {
                List<AssociationStorage> list = associationStorageMapper.getList(new AssociationStorage().setExperimentId(Long.parseLong(xgl.getPktzid())));
                if (list != null && list.size() != 0) {
                    AssociationStorage storage = list.get(0);
                    dataHntPhb.setSampleIdS(storage.getSampleId());
                    dataHntPhb.setSpecIdS(storage.getSpecId());
                    dataHntPhb.setGradeIdS(storage.getGradeId());
                }
            }
            //粗骨料
            if (cgl.getPktzid() != null && !cgl.getPktzid().isEmpty()) {
                List<AssociationStorage> list = associationStorageMapper.getList(new AssociationStorage().setExperimentId(Long.parseLong(cgl.getPktzid())));
                if (list != null && list.size() != 0) {
                    AssociationStorage storage = list.get(0);
                    dataHntPhb.setSampleIdG(storage.getSampleId());
                    dataHntPhb.setSpecIdG(storage.getSpecId());
                    dataHntPhb.setGradeIdG(storage.getGradeId());
                }
            }
            //外加剂1
            if (wjj1.getPktzid() != null && !wjj1.getPktzid().isEmpty()) {
                List<AssociationStorage> list = associationStorageMapper.getList(new AssociationStorage().setExperimentId(Long.parseLong(wjj1.getPktzid())));
                if (list != null && list.size() != 0) {
                    AssociationStorage storage = list.get(0);
                    dataHntPhb.setSampleIdAd(storage.getSampleId());
                    dataHntPhb.setSpecIdAd(storage.getSpecId());
                    dataHntPhb.setGradeIdAd(storage.getGradeId());
                }
            }
            //外加剂2
            if (wjj2.getPktzid() != null && !wjj2.getPktzid().isEmpty()) {
                List<AssociationStorage> list = associationStorageMapper.getList(new AssociationStorage().setExperimentId(Long.parseLong(wjj2.getPktzid())));
                if (list != null && !list.isEmpty()) {
                    AssociationStorage storage = list.get(0);
                    dataHntPhb.setSampleIdAd2(storage.getSampleId());
                    dataHntPhb.setSpecIdAd2(storage.getSpecId());
                    dataHntPhb.setGradeIdAd2(storage.getGradeId());
                }
            }
        }

        //查询协会是否有新增的配合比编号
        Map<String, Object> data_hntphbByBh = dataHntPhbMapper.findDATA_HNTPHBByBh(entity.getProportionPhb());
        if (data_hntphbByBh == null) {
            //新增
            dataHntPhbMapper.addDATA_HNTPHB(dataHntPhb);

        } else {
            //修改
            dataHntPhbMapper.updateDATA_HNTPHB(dataHntPhb);

        }

        log.info("新增/修改协会配合比结束，配合比编号：【{}】", entity.getProportionPhb());
    }
}
